尝试使用Skip方法时,System.Linq.IOrderedQueryable'不包含"跳过"错误的定义

Det*_*ium 3 c# linq entity-framework

我正在尝试实现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;
    }
Run Code Online (Sandbox Code Playgroud)

工作解决方案

takeskip需要是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;
    }
Run Code Online (Sandbox Code Playgroud)

Cod*_*dor 7

参数SkipTake必须是类型int,因为它们分别表示要跳过和采用的元素数量,而不是string问题中的元素.