我有一种情况在下面的嵌套C#LINQ嵌套select查询
--Orders (List)
----Products (List)
------Manufacturers (List)
FIELDS
-Name
-Address
-City
在这种情况下,我需要执行查询,这将在过滤的制造商市并返回Orders, Products & only matching city manufacturers
我试图把以下查询,但我收到所有产品列表即使城市不匹配制造商。
var filteredOrders = from o in Orders
from t in o.Products
where t.Manufacturers.Any(v => v.City == "Hartford")
select o;
或者,即使我从select o
更改为“选择t.Manufacturers”我得到制造商的所有名单,不论城市滤波器。
幸运的是,我得到了与我的场景匹配的W3school SQL示例。 https://www.w3schools.com/sql/trysql.asp?filename=trysql_op_or
SQL查询:
SELECT o.OrderId, p.ProductName, s.*
FROM [Orders] o
JOIN OrderDetails od ON o.OrderId = od.OrderId AND o.orderId = 10248
JOIN Products p ON od.ProductId = p.ProductId
JOIN Suppliers s ON p.SupplierId = s.SupplierId and s.City ='Singapore'
是什么'p.Products'的'p'? – shole
@shole,我的坏,编辑! – Kenz
'Any()'返回true或false,所以如果任何城市是“Hartford”,它将返回true,意味着你什么都不过滤。尝试最简单的确切条款:'哪里t.Manufacturers.City ==“哈特福德”' – shole