//inner join
from a in StoreInCities
join b in CityInfo on a.CityId equals b.ID into c
select c
//left join (right join只是顺序换一下)
from a in StoreInCities
join b in CityInfo on a.CityId equals b.ID into c
//DefaultIfEmpty()是为了达到左连接的目的,不使用DefaultIfEmpty(),相当于是inner join
from d in c.DefaultIfEmpty()
select d
//上面的left join等价于下面的方法语法
StoreInCities
.GroupJoin (
CityInfo,
a => a.CityId,
b => b.ID,
(a, c) =>
new
{
a = a,
c = c
}
)
.SelectMany (
temp0 => temp0.c.DefaultIfEmpty (),
(temp0, d) => d
)
//推荐一个软件,sql,ling方法和ling表达式语法各种切换的软件(linqpad)