日期:2014-05-20  浏览次数:20715 次

这个left,自关联,带条件,的linq语句如何写呢
select A.name,A.name_fullpath,A.GID,A.permissioncode as MenuCode,A.parent_gid,A.ordernum  
         from tb_sys_menu A left join (select GID,parent_gid from tb_sys_menu where menustatus=1) B 
         on A.GID  = B.PARENT_GID  
         where B.GID is null and A.ID_FullPath like 'aa%' and A.menustatus = 1

------解决方案--------------------
本帖最后由 q107770540 于 2013-12-04 14:58:33 编辑

var query=from a in tb_sys_menu
          where a.ID_FullPath.StartWith("aa") && a.menustatus == 1
          join b in tb_sys_menu.Where(x => x.menustatus == 1 && !x.GID.HasValue ).Select(x=>new{x.GID,x.parent_gid})
          on a.GID equals b.PARENT_GID  into lg
          from b in lg.DefaultIfEmpty()
          select new {a.name,a.name_fullpath,a.GID,MenuCode=a.permissioncode,a.parent_gid,a.ordernum  };