Join in LINQ and Entity Framework

c# entity-framework linq

Question

In SQL I to get the distinct statement, I used join to get it as below

select distinct 
    col1 
from 
    table1 a 
inner join 
    table2 b on a.code = b.vcode

How can the same be implemented in linq over Entity Framework?

Please suggest me.

1
10
11/4/2015 4:24:25 PM

Accepted Answer

var result = (from a in table1
              join b in table2 on a.code equals b.vcode
              select a.col1).Distinct();
14
11/4/2015 2:10:38 PM

Popular Answer

You can also use method syntax:

var query = table1.Join(table2,
                        a => a.code,
                        b => b.vcode,
                        (a,b) => a.col1)
                   .Distinct();


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow