开发者

How can I convert this join to LINQ syntax?

开发者 https://www.devze.com 2023-02-25 14:56 出处:网络
I want to retrieve all tools used by products with X = 14, how can I convert this select to LINQ? SELECT DISTINCT t.* FROM Product p

I want to retrieve all tools used by products with X = 14, how can I convert this select to LINQ?

SELECT DISTINCT t.* FROM Product p
INNER JOIN Produc开发者_运维技巧tTool pt ON pt.Product_ID = p.ID
INNER JOIN Tool t ON t.ID = pt.Tools_ID
WHERE p.X = 14

Is GroupJoin what I need or what?

tools.GroupJoin(products, t=>, p=>, ...)
products.GroupJoin(tools, p=>, t=>, ...)


If you have foreign keys setup correctly, the entity framework should pick that relationship up and you should be able to simply do:

var tools = from p in products where p.X == 14 select p.Tool;

0

精彩评论

暂无评论...
验证码 换一张
取 消