简体   繁体   中英

Join in LINQ and Entity Framework

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.

You can also use method syntax:

var query = table1.Join(table2,
                        a => a.code,
                        b => b.vcode,
                        (a,b) => a.col1)
                   .Distinct();
var result = (from a in table1
              join b in table2 on a.code equals b.vcode
              select a.col1).Distinct();

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