<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Chris Woodruff &#187; Queries</title>
	<atom:link href="http://chriswoodruff.com/tag/queries/feed/" rel="self" type="application/rss+xml" />
	<link>http://chriswoodruff.com</link>
	<description>Data Experience Expert</description>
	<lastBuildDate>Mon, 25 Feb 2013 19:14:30 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>OData does not support Select Many Queries</title>
		<link>http://chriswoodruff.com/2010/03/22/odata-does-not-support-select-many-queries/</link>
		<comments>http://chriswoodruff.com/2010/03/22/odata-does-not-support-select-many-queries/#comments</comments>
		<pubDate>Mon, 22 Mar 2010 20:00:35 +0000</pubDate>
		<dc:creator>cwoodruff</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[OData]]></category>
		<category><![CDATA[Queries]]></category>
		<category><![CDATA[Select Many]]></category>

		<guid isPermaLink="false">http://www.chriswoodruff.com/index.php/2010/03/22/odata-does-not-support-select-many-queries/</guid>
		<description><![CDATA[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 [...]]]></description>
				<content:encoded><![CDATA[<p>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 <a href="http://api.visitmix.com/OData.svc">http://api.visitmix.com/OData.svc</a> to accomplish the following: “give me all sessions with an WMV that are tagged Silverlight”</p>
<p>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.</p>
<p>The LINQ statement I thought would work is:</p>
<pre class="code"><span style="color: blue">from </span><span style="color: black">f </span><span style="color: blue">in </span><span style="color: black">Files
</span><span style="color: blue">from </span><span style="color: black">s </span><span style="color: blue">in </span><span style="color: black">f.Sessions
</span><span style="color: blue">from </span><span style="color: black">t </span><span style="color: blue">in </span><span style="color: black">s.Tags
</span><span style="color: blue">where </span><span style="color: black">f.TypeName == </span><span style="color: #dc1414">"WMV" </span><span style="color: black">&amp;&amp; t.TagName == </span><span style="color: #dc1414">"Silverlight"
</span><span style="color: blue">select </span><span style="color: black">f.Url
</pre>
<p><a href="http://11011.net/software/vspaste"></a></span></p>
<p>After discussing it with several people in Redmond, they gave me a A-Ha moment. Here is the dialog we had:</p>
<p>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.</p>
<p>i.e.</p>
<p>
<pre class="code"><span style="color: blue">from </span><span style="color: black">f </span><span style="color: blue">in </span><span style="color: black">Files
</span><span style="color: blue">from </span><span style="color: black">s </span><span style="color: blue">in </span><span style="color: black">f.Sessions
</span><span style="color: blue">from </span><span style="color: black">t </span><span style="color: blue">in </span><span style="color: black">s.Tags
</span><span style="color: blue">where </span><span style="color: black">f.Id == &lt;value&gt;
</span><span style="color: blue">select </span><span style="color: black">s</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>is fine because f.Id is recognized as the key for Files related to the Sessions from the MIX conference.</p>
<p>This however:
<pre class="code"><span style="color: blue">from </span><span style="color: black">f </span><span style="color: blue">in </span><span style="color: black">Files
</span><span style="color: blue">from </span><span style="color: black">s </span><span style="color: blue">in </span><span style="color: black">f.Sessions
</span><span style="color: blue">where </span><span style="color: black">f.Name == “”
</span><span style="color: blue">select </span><span style="color: black">s; </span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>will fail because f.Name is not a key selector.</p>
<p>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…</p>
<p>So this query works:</p>
<p><a href="http://api.visitmix.com/OData.svc/Files(guid'98c77821-982f-4670-8848-001cd763ffbf')/Sessions">http://api.visitmix.com/OData.svc/Files(guid&#8217;98c77821-982f-4670-8848-001cd763ffbf&#8217;)/Sessions</a></p>
<p>Because you have selected an individual file, before navigating to sessions.</p>
<p>But this is no good:</p>
<p><a href="http://api.visitmix.com/OData.svc/Files/Sessions?$filter=Files/Name eq ' '">http://api.visitmix.com/OData.svc/Files/Sessions?$filter=Files/Name eq ‘ ’</a></p>
<p>because you have multiple files when you try to navigate.</p>
]]></content:encoded>
			<wfw:commentRss>http://chriswoodruff.com/2010/03/22/odata-does-not-support-select-many-queries/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
