【发布时间】:2013-01-20 19:29:01
【问题描述】:
如何使用Lazy loading替换Eager Loading?
可以这样说。我有以下类型的 EF 查询,其中有很多 Include keys 。性能方面这非常慢。
那么如何使用Lazy loading 提高以下代码的性能?
from owner in Catalog.Owners
where owner.Key == ownerKey
from invoice in owner.Invoices
where invoice.Provider.Key == providerKey
where invoice.Id == id
select invoice)
.Include(i => i.Owner.Credits)
.Include(i => i.Provider)
.Include(i => i.Items.Select(s => s.Allocation.Service))
.Include(i => i.Items.Select(s => s.Allocation.Pet))
.FirstOrDefault();
如果您能给我一个示例代码说明,那就完美了。
【问题讨论】:
标签: .net performance entity-framework c#-4.0 entity-framework-4.1