Linq to Sql/entity Join

时间:2022-08-06 05:40:07

 

inner join 模板:

  1. var query = from x in db.T1
  2.             join y in db.T2
  3.             on x.Id equals y.Id
  4.             select x;

 

left join模板:

 

  1. var query = from x in db.T1
  2.             join y in db.T2
  3.             on x.yId equals y.Id into temp
  4.             from ret in temp.DefalutIfEmpty()
  5.             select new{ x.Id, ret};

 

经常记不住,这次把它记下来!