Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a right join using LINQ to SQL & C#?

Tags:

c#

sql

linq

I have a problem creating the following SQL Statement using LINQ & 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

I got this:

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);
}

This is not doing a right join, so any ideas?

like image 944
franko_camron Avatar asked Mar 28 '12 19:03

franko_camron


1 Answers

 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 
                 };
like image 175
ionden Avatar answered Nov 04 '22 16:11

ionden