【发布时间】: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