我的项目中有以下查询,执行起来需要花费大量时间。我正在尝试优化它,但未能成功完成。任何建议将不胜感激。
_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);
Include()
gets 转换为 join 并且您在代码中使用了太多联接。您可以借助数据库引擎执行计划来优化索引。
我建议你不要全部使用Include
一气呵成。相反,您中断查询并应用Include
逐个。我的意思是你申请Include, get the result and then apply the
Includeagain and so..By having more than two
Include`影响性能。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)