【发布时间】:2018-09-07 20:52:21
【问题描述】:
我的项目中有以下查询,执行起来很费时间。我正在尝试优化它,但无法成功。任何建议将不胜感激。
_context.MainTable
.Include(mt => mt.ChildTable1)
.Include(mt => mt.ChildTable1.ChildTable2)
.Include(mt => mt.ChildTable3)
.Include(mt => mt.ChildTable3.ChildTable4)
.SingleOrDefault(
mt =>
mt.ChildTable3.ChildTable4.Id == id
&&
mt.ChildTable1.Operation == operation
&&
mt.ChildTable1.Method = method
&&
mt.StatusId == statusId);
【问题讨论】:
-
您是否需要 MainTable、ChildTable1、ChildTable2、ChildTable3 和 ChildTable4 中的每一列,或者您能否缩小结果集中所需的数据列?
-
在此处查看有关显式加载的部分:docs.microsoft.com/en-us/ef/core/querying/related-data 包含过多会导致查询不佳。两种显式加载技术中的任何一种都可以更有效。
标签: entity-framework optimization entity-framework-core