如何Eager Loading
通过使用替换Lazy loading
?
可以这样说。我有以下类型的 EF 查询,其中有很多Include keys
.Performance wise 这非常慢。
那么如何通过使用来提高以下代码的性能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();
如果你能给我一个示例代码解释,那就完美了。