如何在Composite对象中对记录进行排序?

时间:2012-09-17 13:20:24

标签: entity-framework-4.1 wcf-ria-services silverlight-5.0

假设我在DB中有2个表:Student,StudentCourse。

在学生的元数据中,将StudentCourse设置为Composite:

[Include]
[Composition]
public EntityCollection<StudentCourse> StudentCourses { get; set; }

在学生的域名服务中,包括以下学生课程:

public IQueryable<Student> GetStudentByID(int id)
{
   reutrn this.ObjectContext.Students.Include("StudentCourse").Where(s => s.ID == id) as IQueryable<Student>;
}

问题是:我希望StudentCourse的记录可以按学生课程中的一列进行排序,例如,CourseID。

一名学生下的StudentCourse记录实际上是StudentCourse的实体集合。

如何解决此问题?

1 个答案:

答案 0 :(得分:0)

即使在纯SQL中,你所要求的也是不可能的。 您可以尝试,如果您的提供商将支持这样的事情

this.ObjectContext.Students.Include("StudentCourse").Where(s => s.ID == id).OrderBy(x=> x.StudentCourse.First().CourseId) as IQueryable<Student>
相关问题