如何将此连接转换为 LINQ 语法?
我想检索 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=>, ...)
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 ProductTool 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=>, ...)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的外键设置正确,实体框架应该选择该关系,您应该能够简单地执行以下操作:
var tools = from p in products where pX == 14 select p.Tool;
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;