简体   繁体   中英

Convert inner join sql query to linq

I have a sql query which is to be converted to Linq

Select b.title
from TableA as a
inner join TableB as b
on a.Email=b.Email
where a.Title<>b.Title 

the query which i have tried is

var query =from s in TableA
          join r in TableB
          on r.Email equals s.Email

but not able to replicate the where clause which may include many columns

My requirement is i need to compare the 2 tables on a primary key column and then get the other column values which do not match

You need a "select" at the end of the query, and you need to get the inputs in the right order:

var query = from s in TableA
            join r in TableB on s.Email equals r.Email
            where s.Title != r.Title
            select s.Title;

For multiple columns, use an anonymous type:

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM