如何在Where 子句中获得OR?
我正在构建一个临时查询以发送到 SQL,执行以下操作:
var data = from d in db.xxxx select d;
foreach (pattern in user_stuff)
data = data.Where(d=>SqlMethods.Like(d.item,pattern)==true);
问题是 WHERE
子句 AND
组合在一起。 我需要OR
。
知道如何获得OR
吗?
I'm building an ad-hoc query to send to SQL doing the following:
var data = from d in db.xxxx select d;
foreach (pattern in user_stuff)
data = data.Where(d=>SqlMethods.Like(d.item,pattern)==true);
The problem is that the WHERE
clauses get AND
'ed together. I need OR
's.
Any idea how to get an OR
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我回答我自己的问题怎么样:
PredicateBuilder
How about I answer my own question:
PredicateBuilder
您需要构造一个表达式来表示复合 OR 谓词,然后将其传递给Where:
编辑:这可能就是 PredicateBuilder 所做的,只是更混乱:)
You need to construct an Expression to represent the composite OR predicate, then pass that to Where:
EDIT: This is probably what PredicateBuilder does, only a lot messier :)