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;
精彩评论