3

Say I have the following query OData Linq Query (run against http://odata.netflix.com/v2/Catalog):

Genres.Where(x=>x.Name=="Adventures") .Select(y=> new { Genre = y.Name, Movie = y.Titles.Select(l=> new { l.Name, l.AverageRating }) }) 

How could I change this query to give me the rows where AverageRating was 3?

(NOTE: The point of this question is to find out how to do a where clause on properties of an expanded sub list of my main level query item. My real query is not even against the Netflix OData feed.)

2
  • Genres.Where(x=>x.Name=="Adventures" && x.Titles.Any(t => t.AverageRating == 3)) ? Commented Oct 4, 2011 at 15:40
  • @BalaR - Any is not supported in the current version of WCF Data Services. (It is in the next one though). Commented Oct 4, 2011 at 15:43

1 Answer 1

1

The short answer is that it's not possible currently. The $filter always (and only) applies to the top-level entity set. There's currently no way to filter expanded entity sets. The $filter can reach inside the expanded entity sets but the result will always filter the top-level set. In V2 it works for singleton navigation properties (the expression in $filter can traverse those), in V3 you can use the any/all to also incorporate collection navigation properties.

The reason this can't work is that the OData protocol doesn't define the URI syntax for nested filters. In fact it doesn't define almost any operator on the expanded entity sets except for the expansion itself and projections.

Sign up to request clarification or add additional context in comments.

7 Comments

So are you saying that $filter will be supported on expanded entity sets in V3?
No, I said that any/all will be supported which allows you to filter the top-level set based on content of the expanded sets. But it still doesn't allow you to filter the expanded sets.
Ok, thanks. Really what I need is what you have described (filtering top level items based on content of expanded sets). Thanks!
Is the release of OData V3 attached to Visual Studio 11? (Is that something you can even talk about?)
I can't talk exact dates yet (sorry). We have a CTP with support for any/all (blogs.msdn.com/b/astoriateam/archive/2011/06/30/…). You can try it with that.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.