【发布时间】:2020-01-23 07:28:04
【问题描述】:
我想知道是否有人可以告诉我运行这样的 EF 查询之间会有什么性能差异(如果有的话)
var users = _context.Users.Include(p => p.Photos)
.Where(p => p.Photos.Any())
.AsQueryable();
还有这个
var users = _context.Users.Include(p => p.Photos)
.Where(p => p.HasPhoto == true)
.AsQueryable();
在“用户”上检查布尔值“HasPhoto”会更好,还是在 ICollection 上的 .Any() 在大型数据集上也能快速运行? 如何查看速度差异,使用什么工具?
【问题讨论】:
-
请记住,
.Any会自动增加获取Enumerator、调用MoveNext和处理Enumerator的开销。看看source code。
标签: c# entity-framework query-performance