<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" media="screen" href="/styles/xslt/rss.xslt"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:c9="http://channel9.msdn.com">
<channel>
	<title>Channel 9 Forums - Tech Off - LINQ to Entities and using a collection in the query...</title>
	<atom:link rel="self" type="application/rss+xml" href="http://channel9.msdn.com/Forums/rss"></atom:link>
	<image>
		<url>http://mschnlnine.vo.llnwd.net/d1/Dev/App_Themes/C9/images/feedimage.png</url>
		<title>Channel 9 Forums - Tech Off - LINQ to Entities and using a collection in the query...</title>
		<link>http://channel9.msdn.com/Forums</link>
	</image>
	<description>Channel 9 keeps you up to date with the latest news and behind the scenes info from Microsoft that developers love to keep up with. From LINQ to SilverLight – Watch videos and hear about all the cool technologies coming and the people behind them.</description>
	<link>http://channel9.msdn.com/Forums</link>
	<language>en</language>
	<pubDate>Sun, 26 May 2013 04:06:58 GMT</pubDate>
	<lastBuildDate>Sun, 26 May 2013 04:06:58 GMT</lastBuildDate>
	<generator>Rev9</generator>
	<c9:totalResults>8</c9:totalResults>
	<c9:pageCount>-8</c9:pageCount>
	<c9:pageSize>-1</c9:pageSize>
	<item>
		<title>Tech Off - LINQ to Entities and using a collection in the query...</title>
		<description><![CDATA[<p><p align="left">Hey all,<br /><br />This is my first post on channel9 so let me start by saying &quot;Hi!&quot; <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif' alt='Smiley' /> I hope the holiday season has been treating you all well.<br /><br />Now, onto the problem I have been having with LINQ... <br /><br />I am new to LINQ and I have been trying to do something pretty simple with a DB I am playing around with: There are 3 tables, User, UserToClub, and Club. UserToClub maps clubs to a given user and has the user's ID and the club's ID as FKs. When I generated
 EDMX for this DB I got two Entities - User and Club. I just want to filter clubs based on a given list of users, in this case based on a given city. The code compiles fine but I get a runtime error when I try to call Count on myClubs which I guess is when
 the statement gets actually evaluated. The error is:</p>
<p align="left">&nbsp;<em><strong>LINQ to Entities does not recognize the method 'Boolean Contains(Club)' method, and this method cannot be translated into a store expression. (System.NotSupportedException)</strong></em></p>
<p align="left">Any help would be appreciated. The code follows: </p>
<p align="left"></p>
<div class="codeseg">
<div class="codecontent">
<p align="left"><em>//Pick user with the right ID<br /></em><em>var myUser = from aUser in myDB.User<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;where aUser.City.Equals(city)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;select aUser;<br /><br /></em><em>//Filter clubs based on user ID<br /></em><em>var myClubs = from aUser in myUser<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from aClub in myDB.Club<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;where aUser.Club.Contains(aClub)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;select aClub;</em></p>
</div>
</div>
<p></p>
<p align="left"></p>
<p>It seems pretty straightforward to me but I guess I am missing something (yeah, &quot;Doh!&quot;, I know...).<br /><br /><br />Just when I was starting to really love LINQ...</p>
<p align="left">ulas</p></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/447754-LINQ-to-Entities-and-using-a-collection-in-the-query/447754#447754</link>
		<pubDate>Tue, 09 Dec 2008 01:08:55 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/447754-LINQ-to-Entities-and-using-a-collection-in-the-query/447754#447754</guid>
		<dc:creator>Ulas Bardak</dc:creator>
		<slash:comments>8</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/ulas/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - LINQ to Entities and using a collection in the query...</title>
		<description><![CDATA[<p>The most straightforward way I can think to do this involves stepping outside the &quot;from...in&quot; syntax a bit:</p>
<p><em>var myClubs =<br />&nbsp;&nbsp;&nbsp;&nbsp;from aClub in myDB.Club<br />&nbsp;&nbsp;&nbsp;&nbsp;where aClub.Users.Any(aUser =&gt; aUser.City == city)<br />&nbsp;&nbsp;&nbsp;&nbsp;select aClub;<br /><br /></em>This assumes that the navigation property from Club to User is named &quot;Users&quot; (if you haven't changed anything, it's probably &quot;User&quot;).</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/447754-LINQ-to-Entities-and-using-a-collection-in-the-query/3ff3299d2b644025b58d9deb000263b6#3ff3299d2b644025b58d9deb000263b6</link>
		<pubDate>Tue, 09 Dec 2008 02:43:40 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/447754-LINQ-to-Entities-and-using-a-collection-in-the-query/3ff3299d2b644025b58d9deb000263b6#3ff3299d2b644025b58d9deb000263b6</guid>
		<dc:creator>dpratt71</dc:creator>
		<slash:comments>8</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/dpratt71/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - LINQ to Entities and using a collection in the query...</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">dpratt71 said:</div><div class="quoteText">
<p>The most straightforward way I can think to do this involves stepping outside the &quot;from...in&quot; syntax a bit:</p>
<p><em>var myClubs =<br />&nbsp;&nbsp;&nbsp;&nbsp;from aClub in myDB.Club<br />&nbsp;&nbsp;&nbsp;&nbsp;where aClub.Users.Any(aUser =&gt; aUser.City == city)<br />&nbsp;&nbsp;&nbsp;&nbsp;select aClub;<br /><br /></em>This assumes that the navigation property from Club to User is named &quot;Users&quot; (if you haven't changed anything, it's probably &quot;User&quot;).</p>
</div></blockquote>Ah, thanks for the reply <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif' alt='Smiley' /> I will give this a try in a bit and let you know what happens <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif' alt='Smiley' /><br /><br />Quick question though - what is the main reason why my initial version was not working? Did I miss something obvious or is this a matter of lack of support in Linq for a particular type of query? (during runtime since VS does not complain at compiletime).<br /><br />ulas</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/447754-LINQ-to-Entities-and-using-a-collection-in-the-query/1c7eef5140ab43188f759deb000263e1#1c7eef5140ab43188f759deb000263e1</link>
		<pubDate>Tue, 09 Dec 2008 02:47:02 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/447754-LINQ-to-Entities-and-using-a-collection-in-the-query/1c7eef5140ab43188f759deb000263e1#1c7eef5140ab43188f759deb000263e1</guid>
		<dc:creator>Ulas Bardak</dc:creator>
		<slash:comments>8</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/ulas/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - LINQ to Entities and using a collection in the query...</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">ulas said:</div><div class="quoteText">
<blockquote>
<div class="quoteUser">dpratt71 said:</div>
<div class="quoteText">*snip*</div>
</blockquote>
Ah, thanks for the reply <img src="http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif" alt="Smiley"> I will give this a try in a bit and let you know what happens
<img src="http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif" alt="Smiley"><br /><br />Quick question though - what is the main reason why my initial version was not working? Did I miss something obvious or is this a matter of lack of support in Linq for a particular type of query? (during runtime since VS does not complain at compiletime).<br /><br />ulas</div></blockquote>
<p>Basically, it has to do with the fact that the Entity Framework is handed an object graph that represents your query. EF then has to translate that representation into a SQL query. There are many things you can do in code that EF simply cannot translate.</p></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/447754-LINQ-to-Entities-and-using-a-collection-in-the-query/e3a59fd62a6b4be6a6649deb0002640a#e3a59fd62a6b4be6a6649deb0002640a</link>
		<pubDate>Tue, 09 Dec 2008 03:03:39 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/447754-LINQ-to-Entities-and-using-a-collection-in-the-query/e3a59fd62a6b4be6a6649deb0002640a#e3a59fd62a6b4be6a6649deb0002640a</guid>
		<dc:creator>dpratt71</dc:creator>
		<slash:comments>8</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/dpratt71/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - LINQ to Entities and using a collection in the query...</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">dpratt71 said:</div><div class="quoteText">
<p>The most straightforward way I can think to do this involves stepping outside the &quot;from...in&quot; syntax a bit:</p>
<p><em>var myClubs =<br />&nbsp;&nbsp;&nbsp;&nbsp;from aClub in myDB.Club<br />&nbsp;&nbsp;&nbsp;&nbsp;where aClub.Users.Any(aUser =&gt; aUser.City == city)<br />&nbsp;&nbsp;&nbsp;&nbsp;select aClub;<br /><br /></em>This assumes that the navigation property from Club to User is named &quot;Users&quot; (if you haven't changed anything, it's probably &quot;User&quot;).</p>
</div></blockquote>Yup, that worked like a charm <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif' alt='Smiley' /> Thanks a lot! <br /><br />I hope VS will be able to tell what is not supported in LINQ queries at some point. Or even better, may be the Entity Framework will be able to translate everything you can do in code <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-5.gif' alt='Wink' /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/447754-LINQ-to-Entities-and-using-a-collection-in-the-query/2d8c149b81424d1aad3f9deb00026433#2d8c149b81424d1aad3f9deb00026433</link>
		<pubDate>Tue, 09 Dec 2008 07:00:13 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/447754-LINQ-to-Entities-and-using-a-collection-in-the-query/2d8c149b81424d1aad3f9deb00026433#2d8c149b81424d1aad3f9deb00026433</guid>
		<dc:creator>Ulas Bardak</dc:creator>
		<slash:comments>8</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/ulas/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - LINQ to Entities and using a collection in the query...</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">ulas said:</div><div class="quoteText">
<blockquote>
<div class="quoteUser">dpratt71 said:</div>
<div class="quoteText">*snip*</div>
</blockquote>
Yup, that worked like a charm <img src="http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif" alt="Smiley"> Thanks a lot!
<br /><br />I hope VS will be able to tell what is not supported in LINQ queries at some point. Or even better, may be the Entity Framework will be able to translate everything you can do in code
<img src="http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-5.gif" alt="Wink"></div></blockquote>We'll it can't do that (translate everything), but they do have a pattern for letting you describe a proceedure to use for a given method.&nbsp;<br /><br /><a href="http://blogs.msdn.com/efdesign/archive/2008/10/08/edm-and-store-functions-exposed-in-linq.aspx">http://blogs.msdn.com/efdesign/archive/2008/10/08/edm-and-store-functions-exposed-in-linq.aspx</a><br /><br />It would be nice if the model was more 'stood off' I feel, meta data is great - but when you don't even control the source, its just as useless..<br /><br />Even still the design is imperfect but thats the way the ecosystem is for this software..</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/447754-LINQ-to-Entities-and-using-a-collection-in-the-query/7982dfe20a344a2b96a29deb0002645d#7982dfe20a344a2b96a29deb0002645d</link>
		<pubDate>Tue, 09 Dec 2008 09:38:21 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/447754-LINQ-to-Entities-and-using-a-collection-in-the-query/7982dfe20a344a2b96a29deb0002645d#7982dfe20a344a2b96a29deb0002645d</guid>
		<dc:creator>stevo_</dc:creator>
		<slash:comments>8</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/stevo_/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - LINQ to Entities and using a collection in the query...</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">stevo_ said:</div><div class="quoteText">
<blockquote>
<div class="quoteUser">ulas said:</div>
<div class="quoteText">*snip*</div>
</blockquote>
We'll it can't do that (translate everything), but they do have a pattern for letting you describe a proceedure to use for a given method.&nbsp;<br /><br /><a href="http://blogs.msdn.com/efdesign/archive/2008/10/08/edm-and-store-functions-exposed-in-linq.aspx">http://blogs.msdn.com/efdesign/archive/2008/10/08/edm-and-store-functions-exposed-in-linq.aspx</a><br /><br />It would be nice if the model was more 'stood off' I feel, meta data is great - but when you don't even control the source, its just as useless..<br /><br />Even still the design is imperfect but thats the way the ecosystem is for this software.. </div></blockquote>Ah, thanks for the link. I am pretty happy with the expressiveness of Linq in terms of simplifying a lot of mundane tasks one tends to do in code. It is just a
 bit of a downer to get everything compiling happily and then hit a runtime exception when the expression is evaluated. I realize, in a way, this is similar to trying to dividing one variable with another which may happen to be zero which would throw you a
 runtime exception but I just feel like checking which functions you use in the linq expression at compile time wouldn't be as difficult.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/447754-LINQ-to-Entities-and-using-a-collection-in-the-query/3b6142a3e9434278ad8a9deb00026487#3b6142a3e9434278ad8a9deb00026487</link>
		<pubDate>Wed, 10 Dec 2008 00:38:38 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/447754-LINQ-to-Entities-and-using-a-collection-in-the-query/3b6142a3e9434278ad8a9deb00026487#3b6142a3e9434278ad8a9deb00026487</guid>
		<dc:creator>Ulas Bardak</dc:creator>
		<slash:comments>8</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/ulas/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - LINQ to Entities and using a collection in the query...</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">ulas said:</div><div class="quoteText">
<blockquote>
<div class="quoteUser">stevo_ said:</div>
<div class="quoteText">*snip*</div>
</blockquote>
Ah, thanks for the link. I am pretty happy with the expressiveness of Linq in terms of simplifying a lot of mundane tasks one tends to do in code. It is just a bit of a downer to get everything compiling happily and then hit a runtime exception when the expression
 is evaluated. I realize, in a way, this is similar to trying to dividing one variable with another which may happen to be zero which would throw you a runtime exception but I just feel like checking which functions you use in the linq expression at compile
 time wouldn't be as difficult.</div></blockquote>You can use the lambda equivalent too:<br /><br />myDb.user.Where(x=&gt;x.City.Equals(city)).Where(y=&gt;y.Club.Contains(aClub));<br /><br />I think IntelliSense is better at helping you with the lambda. <br /><br /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/447754-LINQ-to-Entities-and-using-a-collection-in-the-query/df5f7d47dbd8401c950d9deb000264cb#df5f7d47dbd8401c950d9deb000264cb</link>
		<pubDate>Thu, 11 Dec 2008 05:35:53 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/447754-LINQ-to-Entities-and-using-a-collection-in-the-query/df5f7d47dbd8401c950d9deb000264cb#df5f7d47dbd8401c950d9deb000264cb</guid>
		<dc:creator>mVPstar</dc:creator>
		<slash:comments>8</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/mVPstar/Discussions/RSS</wfw:commentRss>
	</item>
</channel>
</rss>