【问题标题】:Left Outer Join using LINQ Method Syntax使用 LINQ 方法语法的左外连接
【发布时间】:2015-10-10 13:28:11
【问题描述】:

仍然无法让左外连接在 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 })

【问题讨论】:

标签: c# linq


【解决方案1】:

有点跑题了,但我已经尝试过几次只使用 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()
                        {
                         ...
                        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-18
    • 2013-05-26
    • 2014-03-04
    • 2013-02-04
    • 2021-08-25
    相关资源
    最近更新 更多