【发布时间】:2016-01-06 05:00:02
【问题描述】:
我有以下 SQL 查询,我正在尝试将其转换为 LINQ。
SELECT t1.*
FROM table1 t1
LEFT JOIN table1 t2
ON (t1.MusicId = t2.MusicId AND t1.MusicDetailId > t2.MusicDetailId)
WHERE t2.MusicDetailId IS NULL and t1.SingerId = 2
ORDER BY t1.MusicId
我尝试了以下方法,但没有得到正确的数据。
var query =
from t1 in table1
from t2 in table1
where t1.MusicId == t2.MusicId && t1.MusicDetailId > t2.MusicDetailId
where t1.SingerId == 2 && t2.MusicDetailId == null
orderby t1.MusicId
select t1;
是否有人能够帮助将此 SQL 查询正确转换为 LINQ?
【问题讨论】:
标签: c# sql linq join left-join