Reputation: 24833
What I want to achieve is a simple where clause with expression tree (only):
Tags.Where(t => t.Title == "Exam")
what i have done so far :
ParameterExpression pe = Expression.Parameter(typeof(EfTag), "t");
Expression left = Expression.Property(pe, typeof(EfTag).GetProperty("Title"));
Expression right = Expression.Constant("Exam");
Expression e1 = Expression.Equal(left, right);
var neededTags = myDataContext.Tags.where( e1 /* what should i do here WI?? */ );
Please do not refer me to System.Linq.Dynamic or LinqKit. i need to do this without using any Third part library.
Upvotes: 1
Views: 56
Reputation: 125630
You're almost there. Now that you have the parameter and ==
operator call, you have to combine them together into a Lambda
:
var predicate = Expression.Lambda<Func<EfTag, bool>>(e1, pe);
You can later on use it in Where
call:
var neededTags = myDataContext.Tags.Where(predicate);
Upvotes: 2