方法';跳过';仅支持LINQ to Entities中的排序输入.方法';订购人';必须在方法
本文关键字:方法 输入 排序 Entities 跳过 支持 LINQ to | 更新日期: 2023-09-27 18:24:17
我有上面的错误,这很奇怪,因为我没有使用任何"Skip"方法。
我还注意到,switch语句中的sortOrder为null。
你能帮我找出造成这个错误的原因吗?
我的代码:
public ActionResult Index(string sortOrder, string currentFilter, string searchString, int? page)
{
ViewBag.CurrentSort = sortOrder;
ViewBag.BookingIdSortParm = String.IsNullOrEmpty(sortOrder) ? "RecordId" : "";
ViewBag.ItemSortParm = String.IsNullOrEmpty(sortOrder) ? "Cart" : "";
ViewBag.UserFullNameSortParm = String.IsNullOrEmpty(sortOrder) ? "UserFullName" : "";
ViewBag.StatusCodeSortParm = String.IsNullOrEmpty(sortOrder) ? "StatusCode" : "";
ViewBag.RequestDateSortParm = String.IsNullOrEmpty(sortOrder) ? "RequestDate" : "";
ViewBag.StartDateSortParm = String.IsNullOrEmpty(sortOrder) ? "StartDate" : "";
ViewBag.EndDateSortParm = String.IsNullOrEmpty(sortOrder) ? "EndDate" : "";
if (searchString != null)
{
page = 1;
}
else
{
searchString = currentFilter;
}
ViewBag.CurrentFilter = searchString;
var myBookingList = (from s in SystemDB.Users
where s.UserLogin == strLoginName
join b in SystemDB.Carts on s.DepartmentId equals b.Booking.Item.DepartmentId
where b.Stage != 1 && b.Stage != 5
orderby b.RecordId descending
select b).GroupBy(b => b.CartId).Select(y => y.FirstOrDefault());
if (!String.IsNullOrEmpty(searchString))
{
myBookingList = myBookingList.Where(s => s.RecordId.ToString().Contains(searchString.ToUpper())
|| s.CartId.ToUpper().Contains(searchString.ToUpper())
|| s.Booking.UserFullName.ToUpper().Contains(searchString.ToUpper())
|| s.StatusCode.StatusCodeName.ToUpper().Contains(searchString.ToUpper())
|| s.Booking.RequestDate.ToString().Contains(searchString.ToUpper())
|| s.Booking.StartDate.ToString().Contains(searchString.ToUpper())
|| s.Booking.EndDate.ToString().Contains(searchString.ToUpper()));
}
switch (sortOrder)
{
case "BookingId":
myBookingList = myBookingList.OrderByDescending(s => s.RecordId);
break;
case "Cart":
myBookingList = myBookingList.OrderBy(s => s.CartId);
break;
case "UserFullName":
myBookingList = myBookingList.OrderBy(s => s.Booking.UserFullName);
break;
case "StatusCode":
myBookingList = myBookingList.OrderBy(s => s.StatusCode.StatusCodeName);
break;
case "RequestDate":
myBookingList = myBookingList.OrderByDescending(s => s.Booking.RequestDate);
break;
case "StartDate":
myBookingList = myBookingList.OrderByDescending(s => s.Booking.StartDate);
break;
case "EndDate":
myBookingList = myBookingList.OrderByDescending(s => s.Booking.EndDate);
break;
//default:
// throw new ArgumentException("Bad sort order specified", "sortOrder");
}
int pageSize = 5;
int pageNumber = (page ?? 1);
return View(myBookingList.ToPagedList(pageNumber, pageSize));
}
ToPagedList
的实现将使用Skip
和Take
来获取查询的每个页面。
设置默认排序顺序而不是注释它将起作用
而不是这个
//default:
// throw new ArgumentException("Bad sort order specified", "sortOrder");
尝试此操作或设置一些默认订购
default:
myBookingList = myBookingList.OrderByDescending(s => s.RecordId);
break;
希望它能帮助