我有一个带有服务器端处理的jQuery DataTable,当我Administrator = a.Administrator.FullName
使用data
时,这会给我一个异常错误。
指定的类型成员' FullName' LINQ to Entities
不支持
我的Administrator
课程中有Department
字段,但仍然收到此错误消息。有没有办法解决这个错误?
部门模型
public class Department
{
public int DepartmentID { get; set; }
public string Name { get; set; }
public decimal Budget { get; set; }
public DateTime StartDate { get; set; }
[Display(Name = "Administrator")]
public int? InstructorID { get; set; }
public virtual Instructor Administrator { get; set; }
public virtual ICollection<Course> Courses { get; set; }
讲师班
public class Instructor : Person
{
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
[Display(Name = "Hire Date")]
public DateTime HireDate { get; set; }
public virtual ICollection<Course> Courses { get; set; }
public virtual OfficeAssignment OfficeAssignment { get; set; }
}
Person Class具有FullName
字段
[Display(Name = "Full Name")]
public string FullName
{
get
{
return LastName + ", " + FirstMidName;
}
}
部门总监
public ActionResult DataHandler([ModelBinder(typeof(DataTablesBinder))] IDataTablesRequest requestModel)
{
//IQueryable<Department> query = departmentService.GetDepartments();
IQueryable<Department> query;
using (SchoolContext db = new SchoolContext())
{
query = db.Departments;
var totalCount = query.Count();
// Apply filters for searching
if (requestModel.Search.Value != string.Empty)
{
var value = requestModel.Search.Value.Trim();
query = query.Where(p => p.Name.Contains(value)); //||
//p.Administrator.FullName.Contains(value));
}
var filteredCount = query.Count();
// Sorting
var sortedColumns = requestModel.Columns.GetSortedColumns();
var orderByString = String.Empty;
foreach (var column in sortedColumns)
{
orderByString += orderByString != String.Empty ? "," : "";
orderByString += (column.Data) +
(column.SortDirection ==
Column.OrderDirection.Ascendant ? " asc" : " desc");
}
query = query.OrderBy(orderByString ==
string.Empty ? "BarCode asc" : orderByString);
// Paging
query = query.Skip(requestModel.Start).Take(requestModel.Length);
var data = query.Select(a => new
{
Name = a.Name,
Budget = a.Budget.ToString(),
StartDate = a.StartDate.ToString(),
Administrator = a.Administrator.FullName
}).ToList();
return Json(new DataTablesResponse
(requestModel.Draw, data, filteredCount, totalCount),
JsonRequestBehavior.AllowGet);
}
}
答案 0 :(得分:0)
正如@IvanStoev所提到的,FullName
未被映射,因此对于我的data
,我必须使用FirstName
和LastName
字段。
Administrator = a.Administrator.FirstMidName + " " + a.Administrator.LastName