<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="RSS_xslt_style.asp" version="1.0" ?>
<rss version="2.0" xmlns:WebWizForums="http://syndication.webwiz.co.uk/rss_namespace/">
 <channel>
  <title>DevForce Community Forum : Querying only the Cache</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : DevForce 2009 : Querying only the Cache</description>
  <pubDate>Tue, 12 May 2026 19:36:17 -700</pubDate>
  <lastBuildDate>Wed, 07 Jul 2010 00:11:43 -700</lastBuildDate>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Web Wiz Forums 9.69</generator>
  <ttl>360</ttl>
  <WebWizForums:feedURL>www.ideablade.com/forum/RSS_post_feed.asp?TID=1926</WebWizForums:feedURL>
  <image>
   <title>DevForce Community Forum</title>
   <url>http://www.ideablade.com/forum/forum_images/IdeaBlade_logo_tm.png</url>
   <link>http://www.ideablade.com/forum/</link>
  </image>
  <item>
   <title>Querying only the Cache : Thank you Greg, just wanted to...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1926&amp;PID=7540#7540</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=784" rel="nofollow">kosgia</a><br /><strong>Subject:</strong> 1926<br /><strong>Posted:</strong> 07-Jul-2010 at 12:11am<br /><br />Thank you Greg, just wanted to confirm this.]]>
   </description>
   <pubDate>Wed, 07 Jul 2010 00:11:43 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1926&amp;PID=7540#7540</guid>
  </item> 
  <item>
   <title>Querying only the Cache : You could retrieve just the needed...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1926&amp;PID=7534#7534</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=4" rel="nofollow">GregD</a><br /><strong>Subject:</strong> 1926<br /><strong>Posted:</strong> 06-Jul-2010 at 6:16pm<br /><br />You could retrieve just the needed Employee and Customer before running the query for Orders. That failing, I'm afraid you're stuck, in EF 1.0, with your two forms of the query.]]>
   </description>
   <pubDate>Tue, 06 Jul 2010 18:16:24 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1926&amp;PID=7534#7534</guid>
  </item> 
  <item>
   <title>Querying only the Cache : Greg, thanks for replying.  Indeed...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1926&amp;PID=7478#7478</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=784" rel="nofollow">kosgia</a><br /><strong>Subject:</strong> 1926<br /><strong>Posted:</strong> 01-Jul-2010 at 3:04am<br /><br />Greg, thanks for replying.<DIV>&nbsp;</DIV><DIV>Indeed my initial post is not quite explanatory.</DIV><DIV>i keep telling to myself... Don't write in forums late at night!</DIV><DIV>&nbsp;</DIV><DIV>So this is what i am trying to do.</DIV><DIV>I want to execute a query only in cash to get the orders for a specific Customer and Employee without having to preload Customers and Employees.</DIV><DIV>So i guess i could only write it as:</DIV><DIV><strong>1) DomainModelEntityManager.DefaultManager.Orders.Where(o=&gt; O.Customer_fk_Id == MyCustomerId &amp;&amp;&nbsp;O.Emploeyy_fk_Id == MyEmployeeId).With(QueryStrategy.<FONT size=2>CacheOnly</FONT>).Execute();</strong></DIV><DIV>I would have to use foreign keys here as Customers and Employees don't exist in cache.</DIV><DIV>If no results are returned i would like then to search my database.</DIV><DIV>Of course now i have to rephrase the query to be accepted by The Entity Framework (.NET 3.5 version).</DIV><DIV><DIV><strong>2) DomainModelEntityManager.DefaultManager.Orders.Where(o=&gt; O.Customer.Id == MyCustomerId &amp;&amp;&nbsp;O.Employee.Id == MyEmployeeId).With(QueryStrategy.<FONT size=2>Normal</FONT>).Execute();</strong></DIV><DIV><strong></strong>&nbsp;</DIV><DIV>Is there any other way to accomplish the same effect and not have to write the same query twice, with and without the use of foreign keys?</DIV><DIV>&nbsp;</DIV><DIV>Thank you,</DIV><DIV>Kostas</DIV></DIV>]]>
   </description>
   <pubDate>Thu, 01 Jul 2010 03:04:14 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1926&amp;PID=7478#7478</guid>
  </item> 
  <item>
   <title>Querying only the Cache :   Originally posted by kosgia Finally...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1926&amp;PID=7474#7474</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=4" rel="nofollow">GregD</a><br /><strong>Subject:</strong> 1926<br /><strong>Posted:</strong> 30-Jun-2010 at 3:03pm<br /><br /><table width="99%"><tr><td class="BBquote"><strong><em>Originally posted by kosgia</strong></em><br /><br /><div><div><div><div><strong></strong>&nbsp;</div><div>Finally i would like to ask why when i use the floowing method:</div><div><div><strong>2b) DomainModelEntityManager.DefaultManager.A.Where(A.B_fk_Id= MyId).With(QueryStrategy.<font size="2">Normal</font>).Execute();</strong></div></div><div>i get this exception:</div><div><em>Something in this query is not supported by the Microsoft Entity Framework. Perhaps the query compares entities or non-primitive types.&nbsp;&nbsp; For example, “Where(o =&gt; o == anOrder)” compares Order entities.&nbsp;Instead, please try “Where(o =&gt; o.Id == anOrder.Id)” which compares integer Id values.</em></td></tr></table><br>The Entity Framework (.NET 3.5 version) doesn't like foreign keys and doesn't think they should even be exposed. (This is changed in EF 4.0.)<br><br>You can get what you need as<br><table width="99%"><tr><td><pre class="BBcode"><strong>DomainModelEntityManager.DefaultManager.B.Where(b=&gt; b.Id= MyId).SelectMany(b=&gt;b.A);</strong></pre></td></tr></table><br>or in Employee-Territory terms, as<br><table width="99%"><tr><td><pre class="BBcode"><strong>DomainModelEntityManager.DefaultManager.Territories.Where(t=&gt; t.Id= MyId).SelectMany(t=&gt;t.Employees);</strong></pre></td></tr></table></div></div></div></div>]]>
   </description>
   <pubDate>Wed, 30 Jun 2010 15:03:11 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1926&amp;PID=7474#7474</guid>
  </item> 
  <item>
   <title>Querying only the Cache :  Originally posted by kosgiaI...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1926&amp;PID=7472#7472</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=4" rel="nofollow">GregD</a><br /><strong>Subject:</strong> 1926<br /><strong>Posted:</strong> 30-Jun-2010 at 2:34pm<br /><br /> <table width="99%"><tr><td class="BBquote"><strong><em>Originally posted by kosgia</strong></em><br /><br /><div>I have preloaded all A objects in the Cashe by executing:</div><div><strong>1) DomainModelEntityManager.DefaultManager.A.Execute();</strong></div></td></tr></table> <br>In Silverlight, all data retrieval via the server is asynchronous, so you will need to use ExecuteAsync() rather than Execute() to load the cache.<br><br>&nbsp;<table width="99%"><tr><td class="BBquote"><strong><em>Originally posted by kosgia</strong></em><br /><br /><div>I would like to query the cashe and get only some A objects that reference a specific B object.</div><br><div>So i write something like this:</div><br><div><strong>2) DomainModelEntityManager.DefaultManager.A.Where(A.B.Id = MyId).With(QueryStrategy.<font size="2">CacheOnly</font>).Execute();</strong></div><br><div>This will return nothing as, if i understand correctly, it will search in Cashe for objects B with the specific Id but, since no object B's are loaded, it will fail.</div></td></tr></table> <br>That's true, but if you <i>did </i>have Bs in the cache, you should be able to get your A's much more easily by getting an instance of the desired B, and then referencing its B.As.<br><br>Henceforward, I'm going to use Employees and Territories in my examples instead of As and Bs, as it makes the syntax clearer (and because there actually is a many-to-many association between Employees and Territories in the NorthwindIB database that you can work with). So you would get the desired instance anEmployee of Employee; its collection of related Territories would be anEmployee.Territories.<br><br><br>]]>
   </description>
   <pubDate>Wed, 30 Jun 2010 14:34:03 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1926&amp;PID=7472#7472</guid>
  </item> 
  <item>
   <title>Querying only the Cache : Hi,  i havethe followingcase:  I...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1926&amp;PID=7462#7462</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=784" rel="nofollow">kosgia</a><br /><strong>Subject:</strong> 1926<br /><strong>Posted:</strong> 29-Jun-2010 at 4:10pm<br /><br />Hi, <DIV>i have&nbsp;the following&nbsp;case:</DIV><DIV>&nbsp;</DIV><DIV>I have an object A witch references object B. So, A has a foreign key to B. I would like to preload all A objects in Cache and then execute a query to get a subtotal of A's referencing a particular B. Please confirm me if the following method i use is the recomended one.</DIV><DIV>&nbsp;</DIV><DIV>I have preloaded all A objects in the Cashe by executing:</DIV><DIV><strong>1) DomainModelEntityManager.DefaultManager.A.Execute();</strong></DIV><DIV>I would like to query the cashe and get only some A objects that reference a specific B object.</DIV><DIV>So i write something like this:</DIV><DIV><strong>2) DomainModelEntityManager.DefaultManager.A.Where(A.B.Id = MyId).With(QueryStrategy.<FONT size=2>CacheOnly</FONT>).Execute();</strong></DIV><DIV>This will return nothing as, if i understand correctly, it will search in Cashe for objects B with the specific Id but, since no object B's are loaded, it will fail.</DIV><DIV>if i rewrite 1) as:</DIV><DIV><strong>1a) DomainModelEntityManager.DefaultManager.A.Include("B").Execute();</strong></DIV><DIV>Everything works fine.</DIV><DIV>If i rewrite 2) as:</DIV><DIV><strong>2a) DomainModelEntityManager.DefaultManager.A.Where(A.B_fk_Id= MyId).With(QueryStrategy.<FONT size=2>CacheOnly</FONT>).Execute();</strong></DIV><DIV>Everything works again fine. This time i use the genrated by the object mapper foreign key property in my query predicate and if i understand correctly no access to B property was required to test for B.Id == MyId equality.</DIV><DIV>&nbsp;</DIV><DIV>So here are the possible combinations that work for me.</DIV><DIV>A) Preload B objects with A's</DIV><DIV><strong>1a) DomainModelEntityManager.DefaultManager.A.Include("B").Execute();</strong></DIV><DIV><DIV><strong>2) DomainModelEntityManager.DefaultManager.A.Where(A.B.Id = MyId).With(QueryStrategy.<FONT size=2>CacheOnly</FONT>).Execute();</strong></DIV><DIV>B) Use the genrated by the object mapper foreign key property and and not have to preload B's.</DIV><DIV><DIV><strong>1) DomainModelEntityManager.DefaultManager.A.Execute();</strong></DIV><DIV><DIV><strong>2a) DomainModelEntityManager.DefaultManager.A.Where(A.B_fk_Id= MyId).With(QueryStrategy.<FONT size=2>CacheOnly</FONT>).Execute();</strong></DIV><DIV><strong></strong>&nbsp;</DIV><DIV>Finally i would like to ask why when i use the floowing method:</DIV><DIV><DIV><strong>2b) DomainModelEntityManager.DefaultManager.A.Where(A.B_fk_Id= MyId).With(QueryStrategy.<FONT size=2>Normal</FONT>).Execute();</strong></DIV></DIV><DIV>i get this exception:</DIV><DIV><EM>Something in this query is not supported by the Microsoft Entity Framework. Perhaps the query compares entities or non-primitive types.&nbsp;&nbsp; For example, “Where(o =&gt; o == anOrder)” compares Order entities.&nbsp;Instead, please try “Where(o =&gt; o.Id == anOrder.Id)” which compares integer Id values.</EM></DIV><DIV>&nbsp;</DIV><DIV>I get this exception whenever i try to put in a Where clause a predicate containing a foreign key property and executing the query on the datasource.</DIV><DIV>&nbsp;</DIV><DIV>Thanks in advance,</DIV><DIV>Kostas</DIV></DIV></DIV></DIV>]]>
   </description>
   <pubDate>Tue, 29 Jun 2010 16:10:51 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1926&amp;PID=7462#7462</guid>
  </item> 
 </channel>
</rss>