我试图使用LINQ显示其他表中不存在的行.谁能帮我?
这是我正在使用的sql.
select * from table1
left join table2
on
table1.col1 = table2.col1
and
table1.col2 = table2.col2
where
table2.col1 is null and table2.col2 is null
Run Code Online (Sandbox Code Playgroud)
已经搜索并找到了一些解决方案.这是我到目前为止所做的.
from t1 in table1
where
!(from t2 in table1
join t3 in table2 on
new { t2.col1, t2.col2 }
equals
new { t3.col1, t3.col2 }
select t2.PK).Contains(t1.PK)
select t1
Run Code Online (Sandbox Code Playgroud)
上面的代码运作良好,但我只是想知道这是否是我可以使用的唯一解决方案?我的意思是,不是使用JOIN和CONTAINS方法,我们不能直接使用left join linq和where子句吗?