OData查询可以指定引用嵌套实体的过滤器吗? [英] Can an OData query specify a filter that references a nested entity?

查看:146
本文介绍了OData查询可以指定引用嵌套实体的过滤器吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是设置:我有一个学生",他有一个相关的实体课程"(1对多).每个课程"都有一个相关的实体期间",其中包含课程的所有时间和日期详细信息.我想找回所有在2011年上过课程的学生.

Here is the setup: I've got a "Student" who has a related entity "Course" (1 to many). Each "Course" has a related entity "Period" that contains all of the time and date details of the course. I want to get back all of the students who have had a course in 2011.

我已经尝试过:
〜/Student()?$ expand =课程/期间/amp; $ filter =课程/期间/年份eq 2011
但会导致错误:类型'System.Data.Objects.DataClasses.EntityCollection`1 [[课程]]

I've tried this:
~/Student()?$expand=Course/Period&$filter=Course/Period/Year eq 2011
but it results in an error: No property 'Period' exists in type 'System.Data.Objects.DataClasses.EntityCollection`1[[Course]]

很明显,Period被视为属性而不是实体,但是我很困惑,因为以下查询确实返回了我期望的结果,并且使用几乎相同的语法:
〜/Student()?$ expand =课程/期间& $ select =课程/期间/年份

Clearly, Period is being treated as a property rather than an Entity, but I'm confused, because the following query does return the results I expect, and it uses almost the same syntax:
~/Student()?$expand=Course/Period&$select=Course/Period/Year

那么我在$ filter语法上做错了吗,还是不可能?

So am I doing something wrong with the $filter syntax, or is this not possible?

TIA以获得任何见识.

TIA for any insight.

推荐答案

如果导航属性为单例,则过滤器将起作用,但是由于它是一个集合(1对多),因此该过滤器将不起作用.主要是因为不清楚这意味着什么.您是否要在2011年修完所有课程的学生,还是只修一些课程...等等. 在最新的CTP中( http://www.odata.org /blog/even-more-any-and-all .

The filter would work if the navigation property would be a singleton, but since it's a collection (1 to many) the filter won't work. Mainly because it's unclear what would that mean. Do you want students which have all their courses in 2011 or just some... and so on. In the latest CTP (http://blogs.msdn.com/b/astoriateam/archive/2011/06/30/announcing-wcf-data-services-june-2011-ctp-for-net4-amp-sl4.aspx) There's a support for any and all operators which should allow you to do what you want. For more details see this blog post: http://www.odata.org/blog/even-more-any-and-all.

这篇关于OData查询可以指定引用嵌套实体的过滤器吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆