gpt4 book ai didi

c# - 方法 'Skip' 仅支持 LINQ to Entities 中的排序输入

转载 作者:可可西里 更新时间:2023-11-01 03:06:07 27 4
gpt4 key购买 nike

是什么导致了这个问题?

public ActionResult Index(int page = 0)
{
const int pageSize = 3;
var areas = repo.FindAllAreas();
var paginatedArea = new PaginatedList<Area>(areas, page, pageSize);

return View(paginatedArea);
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace UTEPSA.Controllers
{
class PaginatedList<T> : List<T>
{
public int PageIndex { get; private set; }
public int PageSize { get; private set; }
public int TotalCount { get; private set; }
public int TotalPages { get; private set; }
public PaginatedList(IQueryable<T> source, int pageIndex, int pageSize)
{
PageIndex = pageIndex;
PageSize = pageSize;
TotalCount = source.Count();
TotalPages = (int)Math.Ceiling(TotalCount / (double)PageSize);
//ERROR HERE->>this.AddRange(source.Skip(PageIndex * PageSize).Take(PageSize));
}
public bool HasPreviousPage
{
get
{
return (PageIndex > 0);
}
}
public bool HasNextPage
{
get
{
return (PageIndex + 1 < TotalPages);
}
}
}
}

有什么建议吗?

最佳答案

似乎错误正是它所说的。 “仅允许在已排序的输入上跳过”。搜索此错误,I've found this .

如果您在 Skip 之前包含一个 OrderBy,它应该是固定的:

source.orderBy(???).Skip(PageIndex * PageSize).Take(PageSize)); 

这可能是个问题,因为您正在传递一个通用对象 T。您可能需要扩展您的类以接收另一个参数来指示元素的顺序。

关于c# - 方法 'Skip' 仅支持 LINQ to Entities 中的排序输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3437178/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com