【发布时间】:2012-09-17 13:20:23
【问题描述】:
假设我在 DB 中有 2 个表:Student、StudentCourse。
在 Student 的元数据中,将 StudentCourse 设置为 Composite:
[Include]
[Composition]
public EntityCollection<StudentCourse> StudentCourses { get; set; }
在 Student 的域服务中,包括 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的一个实体集合。
如何解决这个问题?
【问题讨论】:
-
你试过在
.Where(...)之后添加.OrderBy(s => s.CourseId)吗? -
在 lambda 表达式中,s 代表 Student,而不是 StudentCourse。CourseID 不适用于 s。
标签: entity-framework-4.1 wcf-ria-services silverlight-5.0