LINQ 加入帮助
var q = (from Labels in dc.tblArtworkDataLabels select Labels).ToList();
但我需要这样做相当于:
SELECT d.ID, d.labelID, d.dataID, d.data, l.templateID
FROM tblArtworkDataLabels AS d INNER JOIN
tblArtworkData AS l ON d.dataID = l.ID
WHERE (l.templateID = 238)
如何在 LINQ 中执行此操作?
编辑
抱歉!错过了原始 statmenet 上的 WHERE 子句!
var q = (from Labels in dc.tblArtworkDataLabels select Labels).ToList();
But I need this to do the quivalent of:
SELECT d.ID, d.labelID, d.dataID, d.data, l.templateID
FROM tblArtworkDataLabels AS d INNER JOIN
tblArtworkData AS l ON d.dataID = l.ID
WHERE (l.templateID = 238)
How do I do this in LINQ?
Edit
Sorry! Missed the WHERE clause on original statmenet!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您在
tblArtworkData
上有一个正确的外键到tblArtworkDataLabels
上的主键,并且已将它们正确导入到 DBML 设计器中,您可以让 LINQ2SQL 隐式创建联接:请参阅< href="https://stackoverflow.com/questions/5307731/linq-to-sql-multiple-joins-on-multiple-columns-is-this-possible/5309754#5309754">我的回答问题“LINQ to SQL:多个列上的多个联接。这可能吗?”了解隐式连接如何转换为 SQL。
编辑:
如果我误解了您的关系,并且您有许多
tblArtworkDataLabels
到一个tblArtworkData
,您必须以相反的方式进行查询If you have a correct foreign key on
tblArtworkData
to the primary key on thetblArtworkDataLabels
and have imported them correctly into the DBML designer you can have LINQ2SQL implicitly creating the join:See my answer on the question "LINQ to SQL: Multiple joins ON multiple Columns. Is this possible?" for how the implicit join translates to SQL.
Edit:
In the case I misunderstood your relations and you have many
tblArtworkDataLabels
to onetblArtworkData
you have to turn the query the other way around尝试
try