Software Developer, Entrepreneur, Podcaster, Blogger, MVP http://deepfriedbytes.com
Woody's Haven for Geeks
OData does not support Select Many Queries
Over the weekend a fellow developer asked me about how to get a query result from OData using the OData feed from last week’s MIX10 conference http://api.visitmix.com/OData.svc to accomplish the following: “give me all sessions with an WMV that are tagged Silverlight”
I started looking at it and tried to create a LINQ statement for what I thought would be the solution. This was after playing around with the MIX10 OData feed in the Silverlight OData Explorer and not finding a correct URI statement that gave me the result set I was looking for.
The LINQ statement I thought would work is:
from f in Files from s in f.Sessions from t in s.Tags where f.TypeName == "WMV" && t.TagName == "Silverlight" select f.Url
After discussing it with several people in Redmond, they gave me a A-Ha moment. Here is the dialog we had:
If you are trying to select many from OData the OData backend must be able to detect a predicate that can become a key selector for the query.
i.e.
from f in Files from s in f.Sessions from t in s.Tags where f.Id == <value> select s
is fine because f.Id is recognized as the key for Files related to the Sessions from the MIX conference.
This however:
from f in Files from s in f.Sessions where f.Name == “” select s;
will fail because f.Name is not a key selector.
If you think about this in terms of URL’s having to have this key selector for your queries is definitely needed. Whenever you go from one segment to another in the URL you have to have to identify just one item first…
So this query works:
http://api.visitmix.com/OData.svc/Files(guid’98c77821-982f-4670-8848-001cd763ffbf’)/Sessions
Because you have selected an individual file, before navigating to sessions.
But this is no good:
http://api.visitmix.com/OData.svc/Files/Sessions?$filter=Files/Name eq ‘ ’
because you have multiple files when you try to navigate.
Popularity: 100% [?]
One Response to “OData does not support Select Many Queries”
Leave a Reply
It is every man's obligation to put back into the world at least the equivalent of what he takes out of it. - Albert Einstein



[...] issue I was stuck on for awhile. How do relationships work and how can I query collections. This blog post helped me start to understand how keys and collections [...]