我想检索带有X = 14
的产品使用的所有工具,如何将此select转换为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=>, ...)
答案 0 :(得分:3)
如果您正确设置了外键,实体框架应该选择该关系,您应该能够做到:
var tools = from p in products where p.X == 14 select p.Tool;