I am wondering how to pass a property of an object dynamically as a part of the lambda that will be used in the Where method of IQueryable.
Assume I have this code:
var list = new List<Item>();
...
var filtered = list.AsQueryable().Where(x => x.SomePropertyA.Contains(someStringValue));
My task is to make the last statement as a generic method and use a parameter:
IQueryable<Item> SomeMethod(Expression<Func<Item, string>> expr, string stringValue) {
return list.AsQueryable().Where (???);
}
SomeMethod(x => x.SomePropertyA, someStringValue);
SomeMethod(x => x.SomePropertyB, someStringValue);
...
My guts tell me I will have to use Expressions class to call the Contains method of the string that is returned by the expr, but not sure of how to do this, as I am not very familiar with this...