假设我在DB中有两张表格:Student,StudentCourse。如何对Composite对象中的记录进行排序?
在对学生的元数据,设置StudentCourse为复合:
[Include]
[Composition]
public EntityCollection<StudentCourse> StudentCourses { get; set; }
在为学生域名服务,inlcude StudentCourse像:
public IQueryable<Student> GetStudentByID(int id)
{
reutrn this.ObjectContext.Students.Include("StudentCourse").Where(s => s.ID == id) as IQueryable<Student>;
}
的问题是:我想StudentCourse记录可按照来自StudentCourses的列进行排序,例如,CourseID。
一名学生下的StudentCourse记录实际上是StudentCourse的一个实体集合。
如何解决此问题?
你有没有尝试添加'.OrderBy(S => s.CourseId)''之后。哪里(...)'? –
在lambda表达式中,s代表学生,而不是StudentCourse.CourseID不适用于s。 – KentZhou