分页错误:方法“跳过”仅支持LINQ to Entities中的排序输入。必须在方法“跳过”之前调用“OrderBy”方法 [英] Paging Error :The method 'Skip' is only supported for sorted input in LINQ to Entities. The method 'OrderBy' must be called before the method 'Skip'
问题描述
return View(employee.ToPagedList (第?? 1,3));
这里是索引方法
ViewBag.SortNameParameter = string.IsNullOrEmpty(sortBy)? 名称描述
:;
ViewBag.SortGenderParameter = string.IsNullOrEmpty(sortBy)? 性别描述
:性别;
var employee = db.Employees.AsQueryable();
if(searchBy ==Gender)
{
employee = employee.Where(x => x.Gender == search || search == null);
}
else
{
employee = employee.Where(x => x.FUllName .StartsWith(search)|| search == null);
}
switch(sortBy)
{
caseName desc:
employee = employee.OrderByDescending(x => x.FUllName) ;
break;
caseDefault:
employee = employee.OrderBy(x => x.FUllName);
break;
}
return View(employee.ToPagedList(Page ?? 1,3));
}
我没有使用Skip方法...但是有这个错误: / p>
仅在LINQ to
实体中排序输入支持跳过方法。方法OrderBy必须在方法
'跳过之前调用。
我读了相似的帖子
方法Skip仅支持LINQ to Entities中的排序输入。必须在方法跳过之前调用OrderBy方法
如何解决方法Skip只支持排序输入LINQ to Entities。
方法'Skip'仅支持LINQ to Entities中的排序输入。必须在方法跳过之前调用OrderBy方法
并进行了以下更改...
1.Put employee.With代码之前的switch语句:
2.在switch语句中添加一个默认情况,并使其抛出。
caseDefault:
throw new ArgumentException(error,sortBy);
-
使用IOrderedQueryable类型。
IQueryable employee = db.Employees.AsQueryable();
这不会解决问题.. ???
大多是他们使用跳过方法..但我没有...和其他帖子查询是复杂的。
请指出缺少的内容
code>跳过方法。
c $ c> PagedList 为您添加。检查代码。这就是分页的工作原理,采取
和跳过
。
另外我想你的案例陈述是为了
switch(sortBy)
{
caseName desc:
employee = employee.OrderByDescending(x => x.FUllName);
break;
default://不是:caseDefault
employee = employee.OrderBy(x => x.FUllName);
break;
}
I am Doing Paging in MVC on Index Page ..on this Line I got error
return View( employee.ToPagedList(Page ?? 1,3));
here is Index Method
public ActionResult Index(string searchBy, string search, int? Page, string sortBy)
{
ViewBag.SortNameParameter = string.IsNullOrEmpty(sortBy) ? "Name desc"
: "";
ViewBag.SortGenderParameter = string.IsNullOrEmpty(sortBy) ? "Gender desc"
: "Gender";
var employee = db.Employees.AsQueryable();
if (searchBy == "Gender")
{
employee = employee.Where(x => x.Gender == search || search == null);
}
else
{
employee = employee.Where(x => x.FUllName .StartsWith(search ) || search == null);
}
switch (sortBy)
{
case "Name desc":
employee = employee.OrderByDescending(x => x.FUllName);
break;
case "Default":
employee = employee.OrderBy(x => x.FUllName);
break;
}
return View( employee.ToPagedList(Page ?? 1,3));
}
I am not using Skip method ... But there is this error :
The method 'Skip' is only supported for sorted input in LINQ to Entities. The method 'OrderBy' must be called before the method 'Skip'.
I read Similar Posts
How to solve "The method 'Skip' is only supported for sorted input in LINQ to Entities."
ASP.NET MVC 3 PagedList. The method 'Skip' is only supported for sorted input in LINQ to Entities.
and did following changes ...
1.Put employee.Where code before the switch statement:
2.Add a default case in your switch statement, and make it throw. case "Default": throw new ArgumentException("error", sortBy);
Use the type IOrderedQueryable.
IQueryable employee = db.Employees.AsQueryable();
this doesnot solve problem ..
mostly they use to have Skip method .. But i Dont have ... and Other posts query are complex one ..
Please suggest whats missing
You do have a Skip
method.
The PagedList
added it for you. Check the code out. That's how paging works, Take
and Skip
.
Also I think your case statement was meant to be
switch (sortBy)
{
case "Name desc":
employee = employee.OrderByDescending(x => x.FUllName);
break;
default: // Not: case "Default"
employee = employee.OrderBy(x => x.FUllName);
break;
}
这篇关于分页错误:方法“跳过”仅支持LINQ to Entities中的排序输入。必须在方法“跳过”之前调用“OrderBy”方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!