ParameterExpression parameter = Expression.Parameter(typeof(Product), "x");
MemberExpression Left = Expression.MakeMemberAccess(parameter, typeof(Product).GetProperty("Name"));
ConstantExpression Right = Expression.Constant(value, typeof(String));
BinaryExpression expression = Expression.Equal(Left, Right);
LambdaExpression lambada = Expression.Lambda<Func<Product, bool>>(expression, parameter);
Now how do I add this lambada to an instance of an IQuerybale, lets say _query
_query.Where(lambada.Compile());?
I think you just need to change the type of
lambdaNow it is an
Expression<Func<Product, bool>>andIQueryable.Wheretakes that as an argument.Expression.Lambda<TDelegate>returns aTDelegatethat is also aLambdaExpressionwhich is whyExpression.Lambdaline compiles in your case and in my case, butIQueryable.Wherewants to see it as anExpression<Func<Product, bool>>.Something like: