2010-10-13 7 views
1

Comment puis-je mettre en œuvre jointure externe gauche dans le code suivant:jointure externe gauche dans LINQ

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; 
+0

Vous pouvez également consulter quelques exemples sur [Hooked on Linq] (http://www.hookedonlinq.com/OuterJoinSample.ashx). BTW, est-ce Linq aux objets ou avez-vous besoin de cela pour traduire une bonne requête SQL après? – R0MANARMY

Répondre

1

Essayez cela, la clé est l'utilisation de l'opérateur DefaultIfEmpty(). Here is a good article qui traite de l'utilisation de cet opérateur plus en détail.

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

remercie James de m'aider à cet égard – Xulfee

Questions connexes