我正在尝试实现 EF 提供的分页功能。我以为我只需要将简单的 Skip()
和 Take()
添加到我的查询中,但后来我收到了这条消息:
Error 4 'System.Linq.IOrderedQueryable' does not contain a definition for 'Skip' and the best extension method overload 'System.Linq.Queryable.Skip(System.Linq.IQueryable, int)' has some invalid arguments D:\Biblioteker\HourRegistrationApplication\HourRegistrationService\HourRegistrationWCF\Service.cs 190 24 HourRegistrationWCF
我不太确定我需要在这里做什么?我用谷歌搜索了一下,但没有找到任何有用的信息。
GetAllCustomers()
public List<CustomerDTO> GetAllCustomers(string take, string skip)
{
var custList = new List<CustomerDTO>();
var list = DAO.TDKanBanInstance.Customer.OrderBy(x => x.Name).Skip(skip).Take(take).ToList();
foreach (var cust in list)
{
custList.Add(new CustomerDTO()
{
Name = cust.Name
});
}
return custList;
}
可行的解决方案
当然,take
和 skip
需要是 int
。
public List<CustomerDTO> GetAllCustomers(string take, string skip)
{
int skipInt = Int32.Parse(skip);
int takeInt = Int32.Parse(take);
var custList = new List<CustomerDTO>();
var list = DAO.TDKanBanInstance.Customer.OrderBy(x => x.Name).Skip(skipInt).Take(takeInt).ToList();
foreach (var cust in list)
{
custList.Add(new CustomerDTO()
{
Name = cust.Name
});
}
return custList;
}
最佳答案
Skip
和Take
的参数必须是int
类型,因为它们分别表示要跳过和获取的元素数,不是问题中的 string
。
关于c# - System.Linq.IOrderedQueryable' 在尝试使用 Skip 方法时不包含 'Skip' 错误的定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32219722/