views:

38

answers:

1

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("chk") && pgmt.vcr_MetaValue.Contains("true"))
               select pag;
+1  A: 

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;
James
thanks James for helping me in this regards
Xulfee