<?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 : Query Cache and Primary Key Queries </title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : DevForce 2009 : Query Cache and Primary Key Queries </description>
  <pubDate>Tue, 12 May 2026 19:36:12 -700</pubDate>
  <lastBuildDate>Mon, 26 Jul 2010 14:17:42 -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=1927</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>Query Cache and Primary Key Queries  : Ok Greg, thanks for looking into...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1927&amp;PID=7809#7809</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> 1927<br /><strong>Posted:</strong> 26-Jul-2010 at 2:17pm<br /><br /><P>Ok Greg, thanks for looking into this.</P>]]>
   </description>
   <pubDate>Mon, 26 Jul 2010 14:17:42 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1927&amp;PID=7809#7809</guid>
  </item> 
  <item>
   <title>Query Cache and Primary Key Queries  :  Originally posted by kosgiaShouldn&amp;#039;t...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1927&amp;PID=7806#7806</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> 1927<br /><strong>Posted:</strong> 26-Jul-2010 at 12:25pm<br /><br /><table width="99%"><tr><td class="BBquote"><strong><em>Originally posted by kosgia</strong></em><br /><br />Shouldn't the second query be executed and served from the cashe?</td></tr></table> <br /><br />Returning to your original questions: <br /><br />Apparently the cited rules about unrestricted queries, which do apply to DevForce Classic, do not currently apply in either DevForce 2009 or 2010. They were originally implemented in support of something called <em>enumeration entities</em> in DevForce Classic.  Without going into boring detail about those, it suffices to say that they were used with data that seldom changed, and that the benefit of the rules you cited emerges most clearly in the case of such (highly static) data.<br /><br />So, the docs are wrong: in DevForce 2009, if DevForce hasn't seen <em>a specific query</em> before, it will go to the datasource under the default query strategy.<br />]]>
   </description>
   <pubDate>Mon, 26 Jul 2010 12:25:54 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1927&amp;PID=7806#7806</guid>
  </item> 
  <item>
   <title>Query Cache and Primary Key Queries  :  Originally posted by kosgia&amp;lt;P...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1927&amp;PID=7805#7805</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> 1927<br /><strong>Posted:</strong> 26-Jul-2010 at 12:12pm<br /><br /> <table width="99%"><tr><td class="BBquote"><strong><em>Originally posted by kosgia</strong></em><br /><br />&lt;P style="MARGIN: 0in 0in 10pt" =Msonormal&gt;&lt;FONT size=3 face=Calibri&gt;Greg, I am actually working on windows forms and synchronous queries, so my scenario included only these environment settings. </font></p></td></tr></table> <br /><br />Yes, it seems that we reorganized the forums a while back so that Silverlight development isn't separated from WinClient development and I'm just finding out about it. Used to be that if the forum title said "Silverlight", it was <em>only</em> for Silverlight questions, but no more. So you posted in the correct forum.]]>
   </description>
   <pubDate>Mon, 26 Jul 2010 12:12:49 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1927&amp;PID=7805#7805</guid>
  </item> 
  <item>
   <title>Query Cache and Primary Key Queries  : Greg, I am actually working on...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1927&amp;PID=7796#7796</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> 1927<br /><strong>Posted:</strong> 24-Jul-2010 at 4:24am<br /><br /><P style="MARGIN: 0in 0in 10pt" =Ms&#111;normal><FONT size=3 face=Calibri>Greg, I am actually working on windows forms and synchronous queries, so my scenario included only these environment settings. Thanks for taking the time to duplicate it also with Silverlight and asynchronous queries.</FONT></P>]]>
   </description>
   <pubDate>Sat, 24 Jul 2010 04:24:39 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1927&amp;PID=7796#7796</guid>
  </item> 
  <item>
   <title>Query Cache and Primary Key Queries  : You&amp;#039;ve posted in the Silverlight...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1927&amp;PID=7784#7784</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> 1927<br /><strong>Posted:</strong> 23-Jul-2010 at 12:16pm<br /><br />You've posted in the Silverlight forum, but your examples are of synchronous queries. Are you really working in Silverlight?<br /><br /> <table width="99%"><tr><td class="BBquote"><strong><em>Originally posted by kosgia</strong></em><br /><br />Shouldn't the second query be executed and served from the cashe?</td></tr></table> <br /><br />I thought so, but I duplicated your scenario (in Silverlight, using asynchronous queries) and also see the two queries. I'll check into it with the Development team.<br />]]>
   </description>
   <pubDate>Fri, 23 Jul 2010 12:16:46 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1927&amp;PID=7784#7784</guid>
  </item> 
  <item>
   <title>Query Cache and Primary Key Queries  : That&amp;#039;s okDavid, thanks. </title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1927&amp;PID=7781#7781</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> 1927<br /><strong>Posted:</strong> 23-Jul-2010 at 10:52am<br /><br />That's ok&nbsp;David, thanks.]]>
   </description>
   <pubDate>Fri, 23 Jul 2010 10:52:36 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1927&amp;PID=7781#7781</guid>
  </item> 
  <item>
   <title>Query Cache and Primary Key Queries  : On June 29, you opened two topics...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1927&amp;PID=7780#7780</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=23" rel="nofollow">davidklitzke</a><br /><strong>Subject:</strong> 1927<br /><strong>Posted:</strong> 23-Jul-2010 at 10:33am<br /><br />On June 29, you opened two topics on the Forum.&nbsp; One was on "Querying only the Cache" (which we have answered).&nbsp; The other topic is this one on "Query Cache and Primary Key Queries".&nbsp;&nbsp; Instead of opening two support tickets, we only opened a support ticket for "Quering only the Cache".&nbsp; Thank you for bringing this to our attention.&nbsp;&nbsp;We will open a support ticket for "Query Cache and Primary Key Queries".]]>
   </description>
   <pubDate>Fri, 23 Jul 2010 10:33:46 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1927&amp;PID=7780#7780</guid>
  </item> 
  <item>
   <title>Query Cache and Primary Key Queries  : Almost one month has passsed since...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1927&amp;PID=7777#7777</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> 1927<br /><strong>Posted:</strong> 23-Jul-2010 at 1:50am<br /><br /><P>Almost one month has passsed since my initial post. An Ideablade&nbsp;employee response (or from anybody else) would really be appreciated.</P><span style="font-size:10px"><br /><br />Edited by kosgia - 23-Jul-2010 at 1:51am</span>]]>
   </description>
   <pubDate>Fri, 23 Jul 2010 01:50:34 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1927&amp;PID=7777#7777</guid>
  </item> 
  <item>
   <title>Query Cache and Primary Key Queries  : Hi,  I am using DevForce 5.2.6.0. The...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1927&amp;PID=7456#7456</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> 1927<br /><strong>Posted:</strong> 29-Jun-2010 at 8:39am<br /><br /><FONT size=3>Hi,</FONT><DIV>&nbsp;</DIV><DIV><FONT size=3>I am using DevForce 5.2.6.0.</FONT></DIV><DIV><FONT size=3>The folowing is from the product manual for DevForce 2009.</FONT></DIV><DIV>&nbsp;</DIV><DIV><FONT color=#365f92 face="Times New Roman"><FONT color=#365f92 face="Times New Roman"><FONT face="Times New Roman, Times, serif">Query Cache</FONT></FONT></FONT></DIV><DIV><FONT face="Times New Roman, Times, serif"><FONT size=2><FONT size=2>When a </FONT></FONT><FONT color=#244061 size=1><FONT color=#244061 size=1><FONT color=#244061 size=1>EntityManager </FONT></FONT></FONT><FONT size=2><FONT size=2>begins to process a normal query, it checks its </FONT></FONT><B><FONT size=2><FONT size=2>query cache </B></FONT></FONT></FONT><FONT size=2><FONT size=2><FONT face="Times New Roman, Times, serif">to see if it has processed this </FONT></FONT></FONT><FONT size=2><FONT size=2><FONT face="Times New Roman, Times, serif">exact query before. </FONT></FONT></FONT><FONT size=2><FONT size=2><FONT face="Times New Roman, Times, serif">If the </FONT></FONT></FONT><FONT color=#244061 size=1><FONT color=#244061 size=1><FONT color=#244061 size=1 face="Times New Roman, Times, serif">EntityManager </FONT></FONT></FONT><FONT size=2><FONT size=2><FONT face="Times New Roman, Times, serif">finds the query in the query cache, it assumes that the objects which satisfy the query are in </FONT><FONT face="Times New Roman, Times, serif">the entity cache; accordingly, it satisfies the query entirely from the cache without consulting the data source. </FONT><FONT face="Times New Roman, Times, serif">A one-to-m</FONT></FONT></FONT><FONT size=2><FONT size=2><FONT face="Times New Roman, Times, serif">any entity navigation, such as from employee to the employee&#8223;s orders, is translated implicitly to an </FONT></FONT></FONT><FONT size=2><FONT size=2><FONT face="Times New Roman, Times, serif">entity query language (OQL) query that also enters the query cache. The next time the application navigates from </FONT><FONT face="Times New Roman, Times, serif">that same employee to its orders, the </FONT></FONT></FONT><FONT color=#244061 size=1><FONT color=#244061 size=1><FONT color=#244061 size=1 face="Times New Roman, Times, serif">EntityManager </FONT></FONT></FONT><FONT size=2><FONT size=2><FONT face="Times New Roman, Times, serif">will recognize that it has performed the query before and </FONT><FONT face="Times New Roman, Times, serif">look only in the cache for those orders. </FONT><FONT face="Times New Roman, Times, serif">The query cache grows during the course of a session. Certain operations clear it as one of their side-effects; </FONT><FONT face="Times New Roman, Times, serif">removing an entity from the cache is one such operation. The developer can also clear the query cache explicitly. </FONT><FONT face="Times New Roman, Times, serif"><strong>We just said that the EntityManager searches the query cache for an </strong></FONT></FONT></FONT><I><FONT size=2><FONT size=2><FONT face="Times New Roman, Times, serif"><strong>exact match </strong></FONT></I></FONT></FONT><strong><FONT size=2><FONT size=2><FONT face="Times New Roman, Times, serif">of the current query, but that was </FONT></FONT></FONT><FONT size=2><FONT size=2><FONT face="Times New Roman, Times, serif">really a “little white first approximation.” Actually, the E</FONT></FONT></FONT><FONT face="Times New Roman, Times, serif"><FONT size=2><FONT size=2>ntityManager does better than that: it searches </FONT></FONT><I><FONT size=2><FONT size=2>either </I></FONT></strong></FONT></FONT><strong><FONT size=2><FONT size=2><FONT face="Times New Roman, Times, serif">for an </FONT><FONT face="Times New Roman, Times, serif">exact match, </FONT></FONT></FONT><I><FONT size=2><FONT size=2><FONT face="Times New Roman, Times, serif">or for an unrestricted query returning the same type</FONT></I></strong></FONT></FONT><strong><FONT size=2><FONT size=2><FONT face="Times New Roman, Times, serif">. If, for example, you have previously retrieved </FONT></FONT></FONT><FONT size=2><FONT size=2><FONT face="Times New Roman, Times, serif">“all Customers” and now ask for “Customers from Canada”, your new query will be </FONT></FONT></FONT></strong><FONT size=2><FONT size=2><FONT face="Times New Roman, Times, serif"><strong>satisfied from the cache.</strong> </FONT></FONT></FONT></DIV><DIV>&nbsp;</DIV><DIV><FONT color=#365f92><FONT color=#365f92 face="Times New Roman, Times, serif">Primary key queries</FONT></FONT></DIV><DIV><strong><FONT size=2><FONT size=2><FONT face="Times New Roman, Times, serif">A query for business objects by primary key may be resolved entirely in the cache. If we search</FONT></FONT></FONT><FONT face="Times New Roman, Times, serif"><FONT size=1><FONT size=1>33 </FONT></FONT><FONT size=2><FONT size=2>for the employee </FONT></FONT></FONT><FONT size=2><FONT size=2><FONT face="Times New Roman, Times, serif">with Id = „1&#8223; the </FONT></FONT></FONT><FONT color=#244061 size=1><FONT color=#244061 size=1><FONT color=#244061 size=1 face="Times New Roman, Times, serif">EntityManager </FONT></FONT></FONT><FONT size=2><FONT size=2><FONT face="Times New Roman, Times, serif">will try to find it in the cache and, if not found there, will only then look for it in </FONT><FONT face="Times New Roman, Times, serif">the data source. </FONT><FONT face="Times New Roman, Times, serif">The </FONT></FONT></FONT><FONT color=#244061 size=1><FONT color=#244061 size=1><FONT color=#244061 size=1 face="Times New Roman, Times, serif">EntityManager </FONT></FONT></FONT><FONT size=2 face="Times New Roman"><FONT size=2 face="Times New Roman"><FONT face="Times New Roman, Times, serif">treats navigation along a one-to-one relationship, such as from Employee to HomeAddress, as </FONT><FONT face="Times New Roman, Times, serif">a primary key query. Navigation in the parent direction along a one-to-many relationship, such as from an </FONT><FONT face="Times New Roman, Times, serif">OrderDetail to its parent Order, is also a primary key query.</FONT></FONT></FONT></strong></DIV><DIV><strong><FONT size=2 face="Times New Roman"><FONT size=2 face="Times New Roman"></FONT></FONT></strong>&nbsp;</DIV><DIV><FONT face="Times New Roman"><FONT size=3 face="Times New Roman">The default QueryStrategy i use is Normal which, if i am not mistaken, uses an Optimized FetchStrategy, meaning that the EntityManager will try to satisfy queries from the cash first and then from the DataSource as long as it finds them in Query Cashe.</FONT></FONT></DIV><DIV><FONT face="Times New Roman"><FONT size=3 face="Times New Roman"></FONT></FONT>&nbsp;</DIV><DIV><FONT face="Times New Roman"><FONT size=3 face="Times New Roman">I have a business objecr A.</FONT></FONT></DIV><DIV><FONT face="Times New Roman"><FONT size=3 face="Times New Roman">After executing the following code:</FONT></FONT></DIV><DIV><FONT size=3 face="Times New Roman"><strong>DomainModelEntityManager.DefaultManager.A.Execute();</strong></FONT></DIV><DIV><FONT size=3 face="Times New Roman"><strong>DomainModelEntityManager.DefaultManager.A.Where(f =&gt; f.Id == MyId).Execute();</strong></FONT></DIV><DIV><FONT size=3 face="Times New Roman">and having the trace viewer and sql profiler open i can see that 2 queries are executed on database, one for each command.</FONT></DIV><DIV><FONT size=3 face="Times New Roman"></FONT>&nbsp;</DIV><DIV><FONT size=3 face="Times New Roman">Question 1:</FONT></DIV><DIV><FONT size=3 face="Times New Roman">Shouldn't the second query be executed and served&nbsp;from the cashe?</FONT></DIV><DIV><FONT size=3 face="Times New Roman">The first query is an unrestricted query returning objects of type A. An exact match for the second query does not exist on query cashe but an unrestricted query returning the same type (A)&nbsp;exists (First Query), so according to the product manual&nbsp;the second should be&nbsp;served from&nbsp;the cash.</FONT></DIV><DIV><FONT size=3 face="Times New Roman"></FONT>&nbsp;</DIV><DIV><FONT size=3 face="Times New Roman">Question 2:</FONT></DIV><DIV><FONT size=3 face="Times New Roman">I know that A.Id is the primary key for business objects of type A. Does the EntityManager consider the second query to be a Primary Key query? According to the manual "<strong><FONT size=2>If we search</FONT><FONT face="Times New Roman, Times, serif"><FONT size=1><FONT size=1> </FONT></FONT><FONT size=2><FONT size=2>for the employee </FONT></FONT></FONT><FONT size=2><FONT size=2><FONT face="Times New Roman, Times, serif">with Id = „1&#8223; the </FONT></FONT></FONT><FONT color=#244061 size=1><FONT color=#244061 size=1><FONT color=#244061 size=1 face="Times New Roman, Times, serif">EntityManager </FONT></FONT></FONT><FONT size=2><FONT size=2><FONT face="Times New Roman, Times, serif">will try to find it in the cache and, if not found there, will only then look for it in </FONT><FONT face="Times New Roman, Times, serif">the data source.</FONT></FONT></FONT></strong>" it should but, please correct me if i am mistaken, it does not. Does the EntityManager consider as primary key queries only navigation queries or can it distinguish when a user searches only by primary key using the Where(<FONT color=#2b91af size=2><FONT color=#2b91af size=2>Expression</FONT></FONT><FONT size=2>&lt;</FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>Func</FONT></FONT><FONT size=2>&lt;TSource, </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>bool</FONT></FONT><FONT size=2>&gt;&gt; predicate</FONT>) method. What if a business object has a complex primary key?</FONT></DIV><DIV><FONT size=3 face="Times New Roman"></FONT>&nbsp;</DIV><DIV><FONT size=3 face="Times New Roman">To make sure that i use the correct query strategy i also tried writing the above commands as:</FONT></DIV><DIV><FONT face="Times New Roman"><DIV><FONT size=3 face="Times New Roman"><strong>DomainModelEntityManager.DefaultManager.A</strong></FONT></DIV><DIV><FONT size=3 face="Times New Roman"><strong>.With(<FONT color=#0000ff><FONT color=#0000ff>new</FONT></FONT> <FONT color=#2b91af><FONT color=#2b91af>QueryStrategy</FONT></FONT>(<FONT color=#2b91af><FONT color=#2b91af>FetchStrategy</FONT></FONT>.Optimized, <FONT color=#2b91af><FONT color=#2b91af>MergeStrategy</FONT></FONT>.PreserveChanges, <FONT color=#2b91af><FONT color=#2b91af>QueryInversionMode</FONT></FONT>.On))</strong></FONT></DIV><DIV><FONT size=3 face="Times New Roman"><strong>.Execute();</strong></FONT></DIV><DIV><FONT size=3 face="Times New Roman"><strong>DomainModelEntityManager.DefaultManager.A</strong></FONT></DIV><DIV><FONT size=3 face="Times New Roman"><strong>.Where(f =&gt; f.Id == MyId)</strong></FONT></DIV><DIV><FONT size=3 face="Times New Roman"><strong>.With(<FONT color=#0000ff><FONT color=#0000ff>new</FONT></FONT> <FONT color=#2b91af><FONT color=#2b91af>QueryStrategy</FONT></FONT>(<FONT color=#2b91af><FONT color=#2b91af>FetchStrategy</FONT></FONT>.Optimized, <FONT color=#2b91af><FONT color=#2b91af>MergeStrategy</FONT></FONT>.PreserveChanges, <FONT color=#2b91af><FONT color=#2b91af>QueryInversionMode</FONT></FONT>.On))</strong></FONT></DIV><DIV><FONT size=3 face="Times New Roman"><strong>.Execute();</strong></FONT></DIV><DIV><strong><FONT size=3></FONT></strong>&nbsp;</DIV><DIV><FONT size=3>Thank you in advance,</FONT></DIV><DIV><FONT size=3>Kostas.</FONT></DIV></FONT></DIV>]]>
   </description>
   <pubDate>Tue, 29 Jun 2010 08:39:46 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1927&amp;PID=7456#7456</guid>
  </item> 
 </channel>
</rss>