【发布时间】:2011-04-28 00:18:56
【问题描述】:
所以我有这个数据库模型:
Student<->StudentClasses<->Classes
其中 1 个学生链接到多个 StudentClasses,一个班级链接到多个 StudentClasses。
如何编写 LINQ 查询以获取与 ID 为 1 的学生相关联的所有课程?
以下查询引发异常 (“只能在最后一次导航后指定查询选项(orderby、where、take、skip)。”):
var qry = from sc in service.StudentClasses
where sc.StudentId == 1
from c in service.Classes
where c.ClassId == sc.StudentId
select c;
【问题讨论】:
-
这是一个与此处类似的问题:stackoverflow.com/questions/5746992/linq-query-error/… LINQ 不支持您尝试执行的操作。因此,您需要创建多个查询,或者扩展和拉回超出您需要的范围。
-
你在使用 linq to sql 吗?还是其他 ORM?
-
他正在使用 LINQ to ODATA/rest。
标签: c# .net linq wcf-data-services