LINQ 和 OR 标准
如何以编程方式创建 EF 查询(带有 lambda 的扩展方法)。我了解和标准。这是伪代码:
var query = repository.Where(x => x.Name == "aName");
foreach(string filter in filters)
{
query = query.Where(x => x.FilterValue.Contains(filter))
}
但我想要的不是 and 运算符。我想要一个 or 运算符。我该怎么做?如何在代码中创建复杂的条件树?
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 create complex criteria Trees in code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
http://www.albahari.com/nutshell/predicatebuilder.aspx
PrdicateBuilder 是一个不错的解决方案。但它很复杂,不太容易理解。请参阅评论中其他问题的链接。
还发现这很有用:有时从另一个方向来很方便:
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: