【发布时间】:2021-09-11 23:21:42
【问题描述】:
在我们当前的应用程序中,我们在数据层中有以下功能:
public IEnumerable<User> GetUsers(IPagedAndFilteredAndSortedRequest request)
{
var users = dbContext.Users;
//1) "filteredAndSorted" is a result of applying filters and sorts on users
//2) "filteredAndSorted" is OrderedQueriable
//3) "rows" is number of rows to skip based on request.PageSize and request.PageNumber
var result = filteredAndSorted.Skip(rows).Take(request.PageSize);
return result.ToArray();
}
我们需要使用这个方法从数据库中获取所有用户。所以,问题是:
- 将 1 作为 pageNumber 并将 Int32.MaxValue 作为 pageSize 传递是个好主意吗?
- MSSQL 数据库表的最大行数是多少?
【问题讨论】:
-
'MSSQL 数据库表的最大行数是多少?'只需谷歌它,我的伙计/伙计!请参阅:docs.microsoft.com/en-us/sql/sql-server/… 答案:'受限于可用存储'
-
如果你想在一个请求中获取所有记录,请不要使用
.Skip和.Take。 -
摆脱那个讨厌的
ToArray()电话。这是对内存和cpu时间的巨大浪费。此外,如果您在此方法中对数据进行预排序,则您希望返回IOrderedEnumerable。 -
除了是否(以及为什么)您应该希望通过 EF 查询获取所有行之外,是的,如果给定了
GetUsers方法,则选项 1 实际上是唯一的选择。
标签: c# sql-server entity-framework linq-to-entities