我读了这个问题,这与我遇到的问题相同。不幸的是,标记的解决方案没有帮助。我可能误解了关于 LINQ 的一些非常明显的事情。
我正在尝试进行某种反向查找。我需要找到学生注册的所有课程。
这是代码...
public static IQueryable GetCoursesByStudent(string sStudentId)
{
Ld_Sql_ServerDataContext ld_SqlContext = new Ld_Sql_ServerDataContext();
// course-lesson IDs
var activityEnrollmentIds = from ce in ld_SqlContext.YT_STUDENT_COURSE_ENROLLMENT_STATUS
where ce.STUDENT_EMPLOYEE_ID_NR.ToLower() == sStudentId.ToLower()
select ce.TRAINING_ACTIVITY_ID;
// lesson parent course IDs
var parentIds = from c in ld_SqlContext.YT_TRAINING_COMPONENT_RLTNPs
where activityEnrollmentIds.Contains(c.TRAINING_ACTIVITY_ID)
select c.PARENT_TRAINING_ACTIVITY_ID;
// filtered list of courses
var courses = from c in ld_SqlContext.YT_TRAINING_COMPONENTs
where c.TRAINING_ACTIVITY_TYPE_DC == "Course" &&
(activityEnrollmentIds.ToList().Contains(c.TRAINING_ACTIVITY_ID)
|| parentIds.ToList().Contains(c.TRAINING_ACTIVITY_ID))
select c;
return courses;
}
我将结果数据绑定到一个 ASP:ListBox 并在 DataBind() 上引发以下错误...
System.NotSupportedException:不支持使用本地集合的查询。
有人知道发生了什么吗?