Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.Linq.IOrderedQueryable' does not contain a definition for 'Skip' error while trying to use Skip method

I'm trying to implement the paging feature that EF provides. I thought that I only needed to add the simple Skip() and Take() into my query, but then I get this message:

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

I'm not quite sure about what I need to do here? I've googled a bit but didn't find anything useful.

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;
    }

WORKING SOLUTION

The take and skip needs to be int of course.

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;
    }
like image 570
Detilium Avatar asked Oct 24 '25 16:10

Detilium


1 Answers

The arguments of Skip and Take must be of type int, as they indicate the number of elements to skip and take, respectively, not string as in the question.

like image 148
Codor Avatar answered Oct 26 '25 06:10

Codor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!