需要帮助linq查询!

时间:2022-02-13 02:05:38

I am trying to write a query that will search for "orders" that contain a certain "product" and I'm having a little difficulty getting it to work. Basically, this is what I'm trying to do:

我正在尝试编写一个查询,搜索包含某个“产品”的“订单”,并且我在运行时遇到一些困难。基本上,这就是我要做的事情:

Dim orders = From o in db.Orders _
             Where o.OrderProducts.Contains(Function(p) p.ProductID = 123) _
             Select o 

I've also tried with ...

我也试过......

Where o.OrderProducts.Where(Function(p) p.ProductID = 123)

but that doesn't work either. Where am I going wrong? Thanks!

但这也不起作用。我哪里错了?谢谢!

1 个解决方案

#1


Try using Any()

尝试使用Any()

Dim orders = From o in db.Orders _
             Where o.OrderProducts.Any(Function(p) p.ProductID = 123) _
             Select o

#1


Try using Any()

尝试使用Any()

Dim orders = From o in db.Orders _
             Where o.OrderProducts.Any(Function(p) p.ProductID = 123) _
             Select o