IQueryable的IEnumerable的对比资源库中的模式,延迟加载库中、加载、对比、模式

2023-09-03 12:20:52 作者:温唇°Sunshine

我看过一些文章,指出了IEnumerable用来模仿存储过程或限制你的数据库。外部供应商失去了延迟加载能力。

I have read some articles that state that IEnumerable used to mimic stored procedures or restrict your database. Lost lazy loading ability on the external provider.

凡为IQueryable的为开发人员提供更多的灵活性。延迟加载是存在的。

Where as IQueryable to give developers more flexibility. Lazy loading is there.

在性能方面,既消耗显著量的表现..所以哪一个更preferable?

In terms of performance, both consume a significant amount of performance .. so which one is more preferable?

推荐答案

从存储库模式的角度来看,你可以认为它是这样的:

From the perspective of a Repository Pattern, you can think of it this way:

当你想整个列表传递给客户一次性使用的预先加载的IEnumerable 。他们仍然可以添加LINQ条款,但客户不会从延迟执行中受益。

Use an eager loading IEnumerable when you want to pass an entire list to the client in one go. They can still add linq clauses, but the client does not benefit from deferred execution.

使用延​​迟装入的IQueryable ,当你想扩展递延查询功能给客户,允许客户自行添加LINQ条款。这推迟执行整个查询,直到输出需要的。

Use a lazy loading IQueryable when you want to extend deferred querying capabilities to the client, by allowing the client to add their own linq clauses. This defers execution of the entire query until output is required.

另请参见 延迟执行,并渴望评价

 
精彩推荐