我有一个场景需要嵌套处理。
在这种情况下,我需要执行查询,该查询将根据制造商城市进行过滤,并返回
我尝试使用以下查询,但即使城市与制造商不匹配,我仍然得到了所有产品的列表。
--Orders (List)
----Products (List)
------Manufacturers (List)
FIELDS
-Name
-Address
-City
在这种情况下,我需要执行查询,该查询将根据制造商城市进行过滤,并返回
订单、产品和仅匹配城市制造商
。我尝试使用以下查询,但即使城市与制造商不匹配,我仍然得到了所有产品的列表。
var filteredOrders = from o in Orders
from t in o.Products
where t.Manufacturers.Any(v => v.City == "Hartford")
select o;
即使我将select o
更改为 'select 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
是什么意思? - sholewhere t.Manufacturers.City == "Hartford"
。 - Hasan Emrah SüngüManufactures
是一个集合,因此它没有City
属性可供过滤。 - juharr