【问题标题】:EF left joins table everytime I include child每次我包含孩子时,EF 都会左连接表
【发布时间】:2017-04-11 03:09:52
【问题描述】:

我已经阅读了一些关于如何在 EF Core 中包含所有属性的主题。 我有这样的事情:

_dbcontext.Transaction
.Include(x => x.Enterprise).ThenInclude(x => x.Manager)
.Include(x => x.Enterprise).ThenInclude(x=> x.Address)
.Include(x => x.Enterprise).ThenInclude(x=> x.Example)
...

每次包含 Enterprice,entityframework 都会创建一个新的左连接行。结果是这样的:

SELECT TOP(1) x.Id, x.OtherColumnNames...
FROM Transaction as x
LEFT JOIN Enterprise AS e1 on x.EnterpriseId = e1.Id
LEFT JOIN Enterprise AS e2 on x.EnterpriseId = e2.Id
LEFT JOIN Manager AS m1 on e2.ManagerId = m1.Id
LEFT JOIN Enterprise AS e3 on x.EnterpriseId = e3.Id
LEFT JOIN Address AS a1 on e3.AddressId= a1.Id
LEFT JOIN Enterprise AS e4 on x.EnterpriseId = e4.Id
LEFT JOIN Example AS e1 on e4.ExampleId= e1.Id
...

关于如何使 ef 只左加入我的 Enterprise 表有什么建议吗?因为这不是进行数据库调用的好方法,并且会减慢整个查询的速度。

【问题讨论】:

    标签: entity-framework asp.net-core entity-framework-core


    【解决方案1】:

    JOIN 重复是一个已知的 EF Core 问题。不幸的是,它没有在 EF Core 1.1 中修复。根据this thread,该问题被分配给2.0.0里程碑,没有任何预计的发布日期。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-13
      相关资源
      最近更新 更多