2012-03-28 10 views
4

Hey Jungs, die ich mit LINQ & C#wie ein Recht machen join mit LINQ to SQL & C#

select c.IDAddenda, c.Descripcion 
     from CatAddendas c 
right join EmpresaAddenda e on e.IDAddenda = c.IDAddenda 
    where e.rfc = 'SUL010720JN8' 
    order by c.IDAddenda asc 

Ich habe diese

public IEnumerable<CatAddenda> TraeAddendas(string rfc) 
{ 
    DataClasses1DataContext dc = new DataClasses1DataContext(...); 

    return (from adds in dc.EmpresaAddendas 
      cats.IDAddenda into joined 
      where adds.RFC == rfc 
      select adds.CatAddenda); 
} 

Dieses Problem Erstellen Sie die folgende SQL-Anweisung habe macht keinen richtigen Join, also irgendwelche Ideen?

+0

http://stackoverflow.com/questions/2730810/right-outer-join-inlinq – Phil

Antwort

9
var RightJoin = from adds in dc.EmpresaAddendas 
       join cats in CatAddendas 
        on adds.IDAddenda equals cats.IDAddenda into joined 
       from cats in joined.DefaultIfEmpty() 
       select new 
       { 
        Id = cats.IDAddenda, 
        Description = cats.Descripcion 
       }; 
4
var results = from e in EmpresaAddenda 
       join c in CatAddendas 
       on e.IDAddenda equals c.IDAddenda into f 
       from c in f.DefaultIfEmpty() 
       select new 
       { 
        ID = c.IDAddenda, 
        Description = c.Descripcion 
       }; 

können Sie anwenden, wo und um die Ergebnisse auf.