我在视图中使用 MVC 平台和 jqGrid。下面是控制器代码返回 json 到网格的部分
IQueryable<CalendarViewModel> callendars =
from call in (new KYTCDataContext()).Calendars
where call.AcademicYear == id
select Matcher.Calendar(call);
if (jqGridParameters._search != false)
{
callendars = callendars.Where(jqGridParameters.WhereClause);
}
if (jqGridParameters.sidx != null)
callendars = callendars.OrderBy(
jqGridParameters.sidx.Substring(8) + " " + jqGridParameters.sord.ToLower());
var count = callendars.Count();
int pageIndex = jqGridParameters.page;
Matcher 是一个静态类。下面是该类的使用方法
public static class Matcher
{
public static CalendarViewModel Calendar(Calendar call)
{
return new CalendarViewModel
{
ID = call.ID,
Name = call.Name,
StartDate = call.StartDate,
EndDate = call.EndDate,
AcademicYear = call.AcademicYear
};
}
}
在线
var count = callendars.Count();
我收到此错误:
方法 'KYTC.Models.CalendarViewModel Calendar(KYTC.Data.Calendar)' 不支持对 SQL 的转换。
但是当我将 LINQ 查询更改为此:
IQueryable<CalendarViewModel> callendars =
from call in (new KYTCDataContext()).Calendars
where call.AcademicYear == id
select new CalendarViewModel
{
ID = call.ID,
Name = call.Name,
StartDate = call.StartDate,
EndDate = call.EndDate,
AcademicYear = call.AcademicYear
};
我的代码运行良好。
我的班级定义有什么问题?