使用元组列表的 linq to object
我需要在实体框架中查询对象集合并查找满足参数列表的对象。例如,对象可以包含字段(p1、p2、p3、p4、.. pn)。我想找到满足以下条件的 3 个对象 (p1 = 3, p2 = 7, P3 =23), (p1 = 3, p2 = 43, p3 = 45), (p1 = 1, p2 =232, p3 = 321)。
由于集合可能包含许多元素,并且我可能正在寻找许多(例如 80)这样的元组,因此我不想在循环中执行此操作,因为这需要大量往返。我更愿意用单个 LINQ 语句来完成此操作。这可能吗?
谢谢,
杰瑞
I need to query a object collection in Entity framework and find the objects that meet a list of parameters. For example and object could contain fields (p1, p2, p3, p4, .. pn). I want to find the 3 objects for which the following are true (p1 = 3, p2 = 7, P3 =23), (p1 = 3, p2 = 43, p3 = 45), (p1 = 1, p2 =232, p3 = 321).
Since the collection could contain many elements and I could be looking for many (ex. 80) such tuples I do not want to do this in a loop since that would require a lot of round trips. I would prefer to do this is a single LINQ statement. Is this possible?
Thanks,
Jerry
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试以下方法,但我不确定它是否适用于 Linq-to-entity。
You can try following approach, though I'm not sure that it will work with Linq-to-entity.
是的,你可以这样做。只要这样做:
Yes, you could do this. Just do: