2,116 questions
Score of 0
1 answer
139 views
How to apply a two-levels' SelectMany using expressions in a generic way in C#
Let's have 3 entities with the same base class for ID's:
public class EntityBase
{
public int Id { get; set; }
}
public class Company : EntityBase
{
public string Brand { get; set; }
public ...
Score of 8
1 answer
294 views
Difference between Expression.Return and Expression.Goto in C# Expression Trees
I'm experimenting with C# Expression Trees and trying to understand the difference between Expression.Return and Expression.Goto. I can’t create an example where Return and Goto behave differently ...
Score of 2
2 answers
260 views
Why let with where clause can't translate to SQL?
I have a code snippet that uses let with a where clause.
private List<string> Example2()
{
var query1 =
from c in _context.Customers
let custPurchases = _context.Purchases....
Score of 0
1 answer
347 views
How do I make OData parse a filter string into an Expression?
I have a filter string conformant to the OData $filter syntax and wish to parse it into a System.Linq.Expressions expression.
Context: The web API of our cloud application offers querying endpoints ...
Score of 1
1 answer
96 views
"inheritance" between mappings using Expression<Func<...>> for Entity Framework queries
A rather complicated object mapping I've inherited uses static Expression<Func<...>> in the .Select call (from my research these seem to be called "Expression Trees", but for ...
Score of -1
1 answer
95 views
Chain MethodCallExpression with Expression
I am trying to have MethodCallExpression compiled with a lambda expression. Basically i want a method to be called everytime the lambda expression is invoked.
I am not sure i'm even on the right path ...
Score of 0
1 answer
93 views
Moq fully generic Setup with class proxy attempt throws `Late bound operations cannot be performed`
PROBLEM TO SOLVE
I'm trying to create a mock of interface ISomeService using Moq library which will wrap its real implementation SomeService.
Right now I'm doing this manually like this:
var instance =...
Score of 3
1 answer
83 views
When trying to convert a method to expression tree, got an error 'System.Void' cannot be used for return type ''
I'm trying to convert a method to an expression tree for a test, but I got an error
Exception thrown: 'System.ArgumentException' in System.Linq.Expressions.dll Expression of type 'System.Void' cannot ...
Score of 0
0 answers
79 views
How can I create a parameter expression to be used in a func<EndpointAddress> expression with a predefined value?
I am trying to build a Dictionary(Of Type, Func(Of ServiceModel.EndpointAddress)). The func represents a method which takes in a single string parameter which is the service url and returns a ...
Score of 2
2 answers
108 views
Dynamically created event handler that writes ito a `ref` parameter
I want to subscribe to any event existing on a given object, where I don't know the type in advance. I'm generatig event handler at run-time using System.Linq.Expressions.Expression.
The code I have (...
Score of 0
2 answers
154 views
Dynamically Build LINQ Expressions - ToLower and Contains at the same time
I struggle with adding ToLower() to the Contains LINQ Expressions:
Here is the code of mine with dynamic LINQ Expressions (Contains):
private static Expression GetExpressionCase<T>(...
Score of 1
1 answer
94 views
NHibernate - Problem with creating a custom Linq extension
I have such query in NH Linq:
var query = _session
.Query<Revision>()
.Join(
_session.Query<Document>(),
rev => rev.Document,
doc => doc,
(rev,...
Score of 1
2 answers
181 views
Compiled lambda expression leading to new delegate allocations, whereas non-expression version does not
This compiled expression tree...
var param = Expression.Parameter(typeof(int));
var innerParam = Expression.Parameter(typeof(Action<int>));
var inner = Expression.Lambda(innerParam.Type, ...
Score of 3
2 answers
161 views
Expression trees - invoke lambda during loop leads to variable leaking
I have found little issue with expression trees and would like to know whether such is a bug or a feature. I have this code. The first function assigns one to a variable and returns it.
static class ...
Score of 0
0 answers
80 views
Creating a Lambda for LINQ from code gives error message "Parameter could not be translated"
I am attempting to build a lambda from data.
The module entity has an AlgNo property of type string.
I am trying to get a simple sample code to run before attempting the more advanced case.
Consider ...