我试图实现EF提供的分页功能。我认为我只需要将简单的Skip()
和Take()
添加到我的查询中,但接着我收到此消息:
错误4' System.Linq.IOrderedQueryable'不包含' Skip'的定义和最好的扩展方法重载' System.Linq.Queryable.Skip(System.Linq.IQueryable,int)'有一些无效的参数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;
}
答案 0 :(得分:7)
Skip
和Take
的参数必须是int
类型,因为它们分别表示要跳过和占用的元素数量,而不是string
问题