praveen
praveen

Reputation: 12271

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

Upvotes: 1

Views: 1361

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1499760

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;

Upvotes: 4

Related Questions