Sends for the fellow dear visitors:welcome to dongpad!


 Welcome to DongPad!

 msn


预览模式: 普通 | 列表

IQueryable<T> vs IEnumerable<T>

This Article is Published by Live Writer。

IQueryable is a very powerful feature that enables a variety of interesting deferred execution
scenarios (like paging and composition based queries). As with all powerful features, you want to be
careful with how you use it and make sure it is not abused.
It is important to recognize that returning an IQueryable result from your repository enables calling
code to append on chained operator methods to it, and so participate in the ultimate query execution
.
If you do not want to provide calling code this ability, then you should return back IList, List or
IEnumerable results - which contain the results of a query that has already executed
.
For pagination scenarios this would require you to push the actual data pagination logic into the
repository method being called. In this scenario we might update our FindUpcomingDinners() finder
method to have a signature that either returned a PaginatedList:
PaginatedList< Dinner> FindUpcomingDinners(int pageIndex, int pageSize) { }
Or return back an IList, and use a “totalCount” out param to return the total count of Dinners:
IList FindUpcomingDinners(int pageIndex, int pageSize, out int totalCount) { }

From the NerdDiner Pro!

Tags: DongPad

分类:C# | 固定链接 |评论: 0| 引用: 0 | 查看次数: 612 | 返回顶部