我想检索X = 14
产品使用的所有工具,我如何将此选择转换为LINQ?
SELECT DISTINCT t.* FROM Product p
INNER JOIN ProductTool pt ON pt.Product_ID = p.ID
INNER JOIN Tool t ON t.ID = pt.Tools_ID
WHERE p.X = 14
GroupJoin
是我需要的还是什么?
tools.GroupJoin(products, t=>, p=>, ...)
products.GroupJoin(tools, p=>, t=>, ...)
如果外键设置正确,实体框架应该会选择这种关系,并且您应该能够简单地执行:
var tools = from p in products where p.X == 14 select p.Tool;