Join in LINQ and Entity Framework

╄→尐↘猪︶ㄣ 提交于 2020-05-14 16:14:31

问题


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:


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



回答2:


You can also use method syntax:

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


来源:https://stackoverflow.com/questions/33523974/join-in-linq-and-entity-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!