Linq中如何实现inner join、left join


Inner Join 在Linq中的写法如下:

var results = from f in db.Farms
                join fc in db.FarmCategories on f.FarmId equals fc.FarmId
                where f.FarmId.Equals(2)
                select f;


Left Join 在Linq中的写法如下,后面使用 DefaultIfEmpty()

var results = from f in db.Farms
                join fc in db.FarmCategories.DefaultIfEmpty() on f.FarmId equals fc.FarmId
                where f.FarmId.Equals(2)
                select f;


你可能感兴趣的:(开发点滴,join,linq,equals)