Linq 多表查询
//多表查询 两种方法生成的SQL语句是一模一样
//方法一
var query1 = from a in db.as
from b in db.bs.Where(b => b.Id == a.Id)
from c in db.cs.Where(c => c.Id== b.Id).DefaultIfEmpty()
from d in db.ds.Where(d => d.Id== c.Id).DefaultIfEmpty()
select new{}
//方法二
var query2 = from a in db.as
join b in db.bs on b.Id equals a.Id
join c in db.cs on c.Id equals b.Id into ac
join d in db.ds on d.Id equals c.Id into ad
from c in ac.DefaultIfEmpty()
from d in ad.DefaultIfEmpty()
select new{}
Inner join:
var query = from a in db.as
from b in db.bs
from c in db.cs
where as.Id==bs.Id && bs.Id=cs.Id
select new{}