【发布时间】:2013-10-11 13:14:58
【问题描述】:
当查询需要稍后在代码中访问导航属性的大表时(我明确不想使用延迟加载),.Include() 或 .Load() 的性能会更好吗?或者为什么要使用一个而不是另一个?
在此示例中,包含的表都只有大约 10 个条目,而员工有大约 200 个条目,并且可能会发生其中大多数将通过 include 加载,因为它们与 where 子句匹配。
Context.Measurements.Include(m => m.Product)
.Include(m => m.ProductVersion)
.Include(m => m.Line)
.Include(m => m.MeasureEmployee)
.Include(m => m.MeasurementType)
.Where(m => m.MeasurementTime >= DateTime.Now.AddDays(-1))
.ToList();
或
Context.Products.Load();
Context.ProductVersions.Load();
Context.Lines.Load();
Context.Employees.Load();
Context.MeasurementType.Load();
Context.Measurements.Where(m => m.MeasurementTime >= DateTime.Now.AddDays(-1))
.ToList();
【问题讨论】:
标签: c# .net entity-framework