首页 文章

使用LINQ方法语法进行左外连接

提问于
浏览
0

仍然无法使左外连接在LINQ方法语法中正常工作 . 我的结果仍然是INNER JOIN . 我也尝试过使用DefaultIfEmpty(),我只得到结果,好像它是一个INNER JOIN . 看了这个和其他网站上的很多例子 .

这是我正在使用的LINQ . 我知道这是一个INNER JOIN . 如何将其更改为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 })

1 回答

  • 0

    有点偏离主题,但我已经多次尝试通过仅使用linq语法来实现这样的结果,但我从未设法这样做 . 所以现在谈到左连接我更喜欢以下语法,这是有效的 .

    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()
                            {
                             ...
                            }
    

相关问题