码迷,mamicode.com
首页 > 其他好文 > 详细

Linq 单表城市级联

时间:2015-10-16 23:05:47      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:

var list = (from province in db.Areas
        where province.ParentId == 0 && province.IsDel == 0
        join city in db.Areas on province.ID equals city.ParentId into citys
        from ci in citys.DefaultIfEmpty()
        join area in db.Areas on ci.ID equals area.ParentId into areas
        select new
        {
        ID = province.ID,
        Name = province.AreaName,
        FullName = province.FullName,
        Child = (from cy in citys
              where cy.IsDel == 0
              select new
              {
                  ID = cy.ID,
                  Name = cy.AreaName,
                  FullName = cy.FullName,
                  Child = (from ar in areas
                       where ar.IsDel == 0
                       select new
                       {
                       ID = ar.ID,
                       Name = ar.AreaName,
                       FullName = ar.FullName,
                       })
              })
        }).ToList();
return list;

 

Linq 单表城市级联

标签:

原文地址:http://www.cnblogs.com/qingshang/p/4886477.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!