开发者

left outer join in LINQ

开发者 https://www.devze.com 2023-01-20 11:40 出处:网络
how can i implement left outer join in following code: var showmenu = from pag in pagerepository.GetAllPages()

how can i implement left outer join in following code:

var showmenu = from pag in pagerepository.GetAllPages()
               join pgmt in pagerepository.GetAllPageMeta()
               on pag.int_PageId equals pgmt.int_PageId 
               where (pag.int_OrganizationId == layoutrep.GetSidebarDetailById(SidebarDetailsId).int_OrganizationId
               && pag.int_PostStatusId == 2 && pag.bit_ShowInMenu == true) && 
               (pgmt.vcr_MetaKey.Contains开发者_如何学JAVA("chk") && pgmt.vcr_MetaValue.Contains("true"))
               select pag;


Try this, the key is the usage of the DefaultIfEmpty() operator. Here is a good article that discusses usage of this operator in more detail.

var showmenu = from pag in pagerepository.GetAllPages()
               join pgmt in pagerepository.GetAllPageMeta() 
               on pag.int_PageId equals pgmt.int_PageId into leftj
           from pgmt2 in leftj.DefaultIfEmpty()
               where (pag.int_OrganizationId == layoutrep.GetSidebarDetailById(SidebarDetailsId).int_OrganizationId
               && pag.int_PostStatusId == 2 && pag.bit_ShowInMenu == true) && 
               (pgmt2.vcr_MetaKey.Contains("chk") && pgmt2.vcr_MetaValue.Contains("true"))
               select pag;
0

精彩评论

暂无评论...
验证码 换一张
取 消