Why the below code throws ‘… has some invalid arguments at’
var qry = listFoo.Where(lambda);
How should i write my listFoo inorder to call the Where on it by passing the predicate delegate. My entire code follow below,
List<Foo> listFoo = new List<Foo>();
ParameterExpression foo = Expression.Parameter(typeof(Foo), "foo");
MemberExpression bar = Expression.PropertyOrField(foo, "Bar");
ConstantExpression abc = Expression.Constant("abc", typeof(string));
BinaryExpression test = Expression.Equal(bar, abc);
Expression<Func<Foo, bool>> lambda = Expression.Lambda<Func<Foo, bool>>(test, foo);
var qry = listFoo.Where(lambda);
Because your list is not IQueryable. Why don’t you just do this?
If you can’t do that, do this: