Dynamic LINQ – Is There A .NET 4 Version?
You may want to take a look at PredicateBuilder
You may want to take a look at PredicateBuilder
Expression.Quote specifies that a lambda is to be treated as an expression tree and not as a function. It induces closure semantics on its operand. When you are constructing a MethodCallExpression using Expression.Call, any parameters that are lambda expressions (LambdaExpression/Expression<TDelegate>) must use Expression.Quote to wrap the parameter before passing in. So for a parameter of … Read more
It’s hard to mix compiler-generated expression trees and hand-made ones, precisely because of this sort of thing – extracting out the ParameterExpressions is tricky. So let’s start from scratch: ParameterExpression argParam = Expression.Parameter(typeof(Service), “s”); Expression nameProperty = Expression.Property(argParam, “Name”); Expression namespaceProperty = Expression.Property(argParam, “Namespace”); var val1 = Expression.Constant(“Modules”); var val2 = Expression.Constant(“Namespace”); Expression e1 = … Read more
I think I know what the problem is. Your expression returns type object. If you change this to Expression<Func<T, R>> the return type should be correctly inferred, and UnaryExpression (which I will assume is some boxing operation) should not occur. Update: The signature for Include should be: public void Include<T, R>(Expression<Func<T, R>> expression)
Try this: context.People.AddOrUpdate(p => new { p.FirstName, p.LastName }, people);