7

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?

1

2 Answers 2

14
 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 
                 };
Sign up to request clarification or add additional context in comments.

2 Comments

This is left outer join
Are you sure about that?
5
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 
              };

You can apply where and order by on the results.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.