我有一个要转换为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个表,然后获取不匹配的其他列值
答案 0 :(得分:4)
在查询结束时需要“选择”,您需要按正确的顺序获取输入:
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;