我有一个要转换为 Linq 的 sql 查询
Select b.title
from TableA as a
inner join TableB as b
on a.Email=b.Email
where a.Title<>b.Title
我试过的查询是
var query =from s in TableA
join r in TableB
on r.Email equals s.Email
但无法复制可能包含许多列的 where 子句
我的要求是我需要比较主键列上的 2 个表,然后获取不匹配的其他列值
最佳答案
您需要在查询末尾有一个“选择”,并且您需要以正确的顺序获取输入:
var query = from s in TableA
join r in TableB on s.Email equals r.Email
where s.Title != r.Title
select s.Title;
对于多列,使用匿名类型:
var query = from s in TableA
join r in TableB
on new { s.Email, s.Foo } equals new { r.Email, r.Foo }
where s.Title != r.Title
select s.Title;
关于c# - 将内连接 sql 查询转换为 linq,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11774285/