c# - System.Linq.IOrderedQueryable' 在尝试使用 Skip 方法时不包含 'Skip' 错误的定义

标签 c# linq entity-framework

我正在尝试实现 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;
    }

可行的解决方案

当然,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;
    }

最佳答案

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

关于c# - System.Linq.IOrderedQueryable' 在尝试使用 Skip 方法时不包含 'Skip' 错误的定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32219722/

相关文章:

c# - 遍历数组,将值相互绑定(bind)

c# - 按值过滤 linq 查询

c# - 将默认 where 子句添加到 linq-to-sql 表

c# - 使用 EF 将多个一对多关系添加到一张表

c# - 电话簿 - 进入类(class)列表

c# - 无法在客户端解码证书 new X509Certificate2()

c# - 如何按长度的字母顺序对字符串数组进行排序?

c# - 包含子类型的 Linq 查询

c# - 错误 175 : The ADO. 具有不变名称 'MySql.Data.MySqlClient' 的 NET 提供程序未在计算机或应用程序配置文件中注册

c# - 创建要应用于 IQueryable 的动态搜索的最简单方法