你的位置:首页 > ASP.net教程

[ASP.net教程]linq 多个left join 和 sql union all


 (
  from s in Base_SysMenus
  join r in Base_RoleRights on s.Menu_Id equals r.Menu_Id into temp
  from s_r in temp.DefaultIfEmpty()
 
  join u in Base_UserRoles on s_r.Roles_ID equals u.Roles_ID into temp2
  from t in temp2.DefaultIfEmpty()
  where s.Target=="Iframe" && t.User_ID=="48f3889c-af8d-401f-ada2-c383031af92d" && s.DeleteMark==1
  select new{Menu_Id= s.Menu_Id}
 ).Union(
  from s in Base_SysMenus
  join r in Base_UserGroupRights on s.Menu_Id equals r.Menu_Id into temp
  from s_r in temp.DefaultIfEmpty()
 
  join u in Base_UserInfoUserGroups on s_r.UserGroup_ID equals u.UserGroup_ID into temp2
  from t in temp2.DefaultIfEmpty()
  where s.Target=="Iframe" && t.User_ID=="48f3889c-af8d-401f-ada2-c383031af92d" && s.DeleteMark==1
  select new{Menu_Id= s.Menu_Id}
 ).Union(
  from s in Base_SysMenus
  join r in Base_UserRights on s.Menu_Id equals r.Menu_Id into temp
  from s_r in temp
  where s.Target=="Iframe" && s_r.User_ID=="48f3889c-af8d-401f-ada2-c383031af92d" && s.DeleteMark==1
  select new{Menu_Id= s.Menu_Id}
 )
 
参考资料 : http://www.cnblogs.com/xlhblogs/archive/2012/01/17/2324478.html