0

Still can't get a left outer join to work correctly in LINQ Method Syntax. My results are still INNER JOIN. I have tried using DefaultIfEmpty() as well, I only get the results as if it were an INNER JOIN. Looked at many examples on this and other sites.

Here's the LINQ I'm using. I know it's an INNER JOIN here. How can it be changed to be a LEFT OUTER?

ICD10s
.Join(ICD10CategoryPairs,
left => new { left.Code },
right => new { right.Code },
(left, right) => new { xx = left, yy = right })
.OrderBy(r => r.yy.Category)
.Select(t => new { Code = t.xx.Code, Description = t.xx.Description, Category = t.yy.Category })
Intensivist
  • 767
  • 2
  • 7
  • 19
  • Possible duplicate of [LEFT OUTER JOIN in LINQ](http://stackoverflow.com/questions/3404975/left-outer-join-in-linq) – Vova Oct 10 '15 at 13:52
  • Have you taken a look at this? https://msdn.microsoft.com/en-us/library/bb397895.aspx – maniak1982 Oct 10 '15 at 14:01

1 Answers1

0

A bit off topic but I've tried several times to achieve such a result from using only linq syntax but I never managed to do so. So nowadays when it comes to left joins i prefer the following syntax, which works.

    var dd = from document in sds.documents
                        join documentcategory in sds.documentcategories on document.documentcategoryid equals documentcategory.documentcategoryid
                        join documenttype in sds.documenttypes on document.documenttypeid equals documenttype.documenttypeid
                        join geodocument in sds.geodocuments on document.documentid equals geodocument.documentid into geod from geodocument in geod.DefaultIfEmpty()
                        join geocatalog in sds.geocatalogs on geodocument.geocatalogid equals geocatalog.geocatalogid into geoc from geocatalog in geoc.DefaultIfEmpty()
                             where (document.filename.Contains(txt))
                        select new DTO.Documents()
                        {
                         ...
                        }
elasticrash
  • 1,181
  • 1
  • 12
  • 30