linq如何选择具有子集合的父集合,该子集合包含一个或多个值数组(或列表)
这似乎很容易
var orx = gg.Where(x=>x.ProductAttributes.Any (pa =>pa.AttributeId == "home"));
当产品属性的值为“home”时,
返回 gg我需要它返回 gg 具有数组中的产品属性值的位置 IE
var orx = gg.Where(x=>x.ProductAttributes.Any (pa =>pa.AttributeId in "home,work"));
This seems like it would be easy enough
var orx = gg.Where(x=>x.ProductAttributes.Any (pa =>pa.AttributeId == "home"));
returns gg when product attributes has a value of "home"
I need it to return where and gg has product attribute values from an array
i.e.
var orx = gg.Where(x=>x.ProductAttributes.Any (pa =>pa.AttributeId in "home,work"));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您的列表与您的示例一样可靠,那么...
甚至
"home,work".Contains(pa.AttributeId)
应该可以工作。 (我绝不推荐这样做,除非您可以确保 AttributeId 不会是任何列表单词的子字符串..例如“me”)what about...
or even
"home,work".Contains(pa.AttributeId)
should work, if your list is as reliable as your example. (I by no mean recommend this unless you can ensure that AttributeId will not be a substring of any of the list words.. such as "me")使用 Enumerable.Contains():
Using Enumerable.Contains():