how can I programmatically create an EF query (extension methods with lambda). I understand the and criteria. Here is the pseudo-code:
var query = repository.Where(x => x.Name == "aName");
foreach(string filter in filters)
{
query = query.Where(x => x.FilterValue.Contains(filter))
}
But what I want is not an and operator. I would like an or operator. How do I do this? How can I creat开发者_JS百科e complex criteria Trees in code?
http://www.albahari.com/nutshell/predicatebuilder.aspx
PrdicateBuilder is a nice solution. But it is complicated and not so easy to understand. See Link to other question in comment.
Also found this useful: Sometimes it is convenient to come from the other direction:
string[] filter = {"A", "B"};
var returnValue = repository
.Where(x => x.Name == "aName")
.Where(x => filter.Any(f => (x.FilterValue).Contains(f)))
.ToList();
精彩评论