<?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 : Cache is bypassed (new case) when grouping entities</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : DevForce 2010 : Cache is bypassed (new case) when grouping entities</description>
  <pubDate>Wed, 13 May 2026 17:22:30 -700</pubDate>
  <lastBuildDate>Fri, 09 Dec 2011 14:04:30 -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=3134</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>Cache is bypassed (new case) when grouping entities : Thanks Denis,your suggestion does...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3134&amp;PID=12203#12203</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1263" rel="nofollow">Frederic</a><br /><strong>Subject:</strong> 3134<br /><strong>Posted:</strong> 09-Dec-2011 at 2:04pm<br /><br />Thanks Denis,<div><br></div><div>your suggestion does the trick... spot on!</div><div><br></div><div>I was hoping to apply the same query strategy on all my project queries but that did not work for queries returning scalar results:</div><div><span ="Apple-style-span" style=": rgb251, 251, 253; "><em></span>This query cannot have a FetchStrategy of DataSourceAndCache. DataSourceAndCache implies a union of the results of a DataSource query and a CacheOnly query. This query returns a scalar result and the union &nbsp;of two scalar values is undefined.<span ="Apple-style-span" style=": rgb251, 251, 253; "></em></span></div><div><span ="Apple-style-span" style=": rgb251, 251, 253; "><br></span></div><div><span ="Apple-style-span" style=": rgb251, 251, 253; ">I have read both articles discussing query inversion and cache management but I would lie if I was to pretend I understood it all :)</span></div><div><br></div><div>Nethertheless, Your suggestion helped me to make a good progress and I thank you for that.</div><div><br></div><div>Frederic</div>]]>
   </description>
   <pubDate>Fri, 09 Dec 2011 14:04:30 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3134&amp;PID=12203#12203</guid>
  </item> 
  <item>
   <title>Cache is bypassed (new case) when grouping entities : Hi Frederic;We do QueryInversion...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3134&amp;PID=12189#12189</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=912" rel="nofollow">DenisK</a><br /><strong>Subject:</strong> 3134<br /><strong>Posted:</strong> 08-Dec-2011 at 6:13pm<br /><br />Hi Frederic;<div><br></div><div>We do QueryInversion to determine whether a query can be satisfied from the cache. As it turns out, not all queries can be inverted and this includes queries that involve projections (Select, SelectMany) such as in your case.</div><div><br></div><div>When this happens, we recommend that you force a query to go to the cache by specifying a different QueryStrategy with the query. Here are 2 examples.</div><div><br></div><div><table width="99%"><tr><td><pre class="BBcode"></div><div><div>var orderList = manager.GetQuery&lt;Order&gt;().<b>With(QueryStrategy.CacheOnly)</b></div><div>&nbsp; &nbsp; &nbsp; &nbsp; .GroupBy(o =&gt; new { o.CustomerID, o.EmployeeID })</div><div>&nbsp; &nbsp; &nbsp; &nbsp; .Where(g =&gt; (g.Count() &gt; 2))</div><div>&nbsp; &nbsp; &nbsp; &nbsp; .SelectMany(g =&gt; g, (g, order) =&gt; order);</div></div><div></pre></td></tr></table></div><div><br></div><div>or</div><div><br></div><div><div><table width="99%"><tr><td><pre class="BBcode"></div><div><b>var DataSourceAndCache = new QueryStrategy(FetchStrategy.DataSourceAndCache, MergeStrategy.PreserveChanges, QueryInversionMode.Try);</b></div><div><b><br></b></div><div><div>var orderList = manager.GetQuery&lt;Order&gt;().<b>With(DataSourceAndCache)</b></div><div>&nbsp; &nbsp; &nbsp; &nbsp; .GroupBy(o =&gt; new { o.CustomerID, o.EmployeeID })</div><div>&nbsp; &nbsp; &nbsp; &nbsp; .Where(g =&gt; (g.Count() &gt; 2))</div><div>&nbsp; &nbsp; &nbsp; &nbsp; .SelectMany(g =&gt; g, (g, order) =&gt; order);</div></div><div></pre></td></tr></table></div></div><div><br></div><div>Please see&nbsp;<a href="http://drc.ideablade.com/xwiki/bin/view/&#068;ocumentati&#111;n/query-inversi&#111;n" target="_blank">http://drc.ideablade.com/xwiki/bin/view/Documentation/query-inversion</a>&nbsp;and&nbsp;<a href="http://drc.ideablade.com/xwiki/bin/view/&#068;ocumentati&#111;n/query-cache" target="_blank">http://drc.ideablade.com/xwiki/bin/view/Documentation/query-cache</a>&nbsp;for more discussions on determining whether a query can be satisfied against the cache.</div>]]>
   </description>
   <pubDate>Thu, 08 Dec 2011 18:13:07 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3134&amp;PID=12189#12189</guid>
  </item> 
  <item>
   <title>Cache is bypassed (new case) when grouping entities : Good afternoon,I have previously...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3134&amp;PID=12185#12185</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1263" rel="nofollow">Frederic</a><br /><strong>Subject:</strong> 3134<br /><strong>Posted:</strong> 08-Dec-2011 at 1:21pm<br /><br />Good afternoon,<div><br></div><div>I have previously posted a problem about devforce queries bypassing the cache. That problem was solved using a more recent version of Devforce. Today I have installed what I believe is the latest versaion of Devforce but I found a new case of the cache being bypassed.</div><div><br></div><div>I'm using Devforce 2010, version 6.1.3.3 on SQL Server 2008 R2.</div><div><br></div><div>Say I want to group orders by customerId and employeeId and take all orders where the count of the grouping is say above 2.</div><div><br></div><div>The query would look like this:</div><div><span ="Apple-style-span" style=": rgb251, 251, 253; "><table width="99%"><tr><td><pre class="BBcode"></span><span ="Apple-style-span" style=": rgb251, 251, 253; "><font color=BLUE></span></div><div><div><span ="Apple-tab-span" style="white-space:pre">				</span>var orderList = manager.GetQuery&lt;Order&gt;()</div><div><span ="Apple-tab-span" style="white-space:pre">						</span>.GroupBy(it =&gt; new { it.CustomerID, it.EmployeeID })</div><div><span ="Apple-tab-span" style="white-space:pre">						</span>.Where(g =&gt; (g.Count() &gt; 2))</div><div><span ="Apple-tab-span" style="white-space:pre">						</span>.SelectMany(g =&gt; g, (g, order) =&gt; order);</div></div><div><span ="Apple-style-span" style=": rgb251, 251, 253; "></font></span><span ="Apple-style-span" style=": rgb251, 251, 253; "></pre></td></tr></table></span></div><div>This query gives me all orders meeting the criteria but is always executed against the database server.</div><div><br></div><div>So if I create a new employee, a new customer and create 3 new orders for that new customer placed by my new employee, now the above query does not returns my new orders.</div><div><br></div><div>Though, employee count is now one more than at the start of the program, so is customer and order count is 3 more than at the start but still my groupby query does not see the new orders.</div><div><br></div><div>If I then apply changes to the database using the <span ="Apple-style-span" style=": rgb251, 251, 253; "><table width="99%"><tr><td><pre class="BBcode"></span><span ="Apple-style-span" style=": rgb251, 251, 253; "><font color=BLUE></span>manager.SaveChanges();<span ="Apple-style-span" style=": rgb251, 251, 253; "></font></span><span ="Apple-style-span" style=": rgb251, 251, 253; "></pre></td></tr></table></span>&nbsp;command, the group by query shows my new orders.</div><div><br></div><div>I feel this is not right, I wish all my queries to hit the cache first then the database. How can I do so when using grouping queries?</div><div><br></div><div><span ="apple-style-span"=""><div style="text-align: left; : rgb251, 251, 253; "><span ="apple-style-span"="">Thanks a lot for your support</span></div><div style="text-align: left; : rgb251, 251, 253; "><span ="apple-style-span"=""><br></span></div><div style="text-align: left; : rgb251, 251, 253; "><span ="apple-style-span"="">Frederic</span></div><div><span ="apple-style-span"=""><br></span></div><div><span ="apple-style-span"="">Sample code:</span></div><div><span ="apple-style-span"=""><span ="Apple-style-span" style=": rgb251, 251, 253; "><table width="99%"><tr><td><pre class="BBcode"></span></span><span ="Apple-style-span" style=": rgb251, 251, 253; "><font color=BLUE></span></div><div><span ="apple-style-span"=""><div>NorthwindIB manager = new NorthwindIB(</div></span></div></span></div><blockquote style="margin: 0 0 0 40px; border: n&#111;ne; padding: 0px;"><div><span ="apple-style-span"=""><div><span ="apple-style-span"=""><div>shouldConnect: true,</div></span></div></span></div></blockquote><blockquote style="margin: 0 0 0 40px; border: n&#111;ne; padding: 0px;"><div><span ="apple-style-span"=""><div><span ="apple-style-span"=""><div>dataSourceExtension: String.Empty,</div></span></div></span></div></blockquote><blockquote style="margin: 0 0 0 40px; border: n&#111;ne; padding: 0px;"><div><span ="apple-style-span"=""><div><span ="apple-style-span"=""><div>entityServiceOption: IbEm.EntityServiceOption.UseLocalService,</div></span></div></span></div></blockquote><blockquote style="margin: 0 0 0 40px; border: n&#111;ne; padding: 0px;"><div><span ="apple-style-span"=""><div><span ="apple-style-span"=""><div>compositionContextName: String.Empty);</div></span></div></span></div></blockquote><div><span ="apple-style-span"=""><div><span ="apple-style-span"=""><div><br></div><div>var employeeQuery = manager.GetQuery&lt;Employee&gt;();</div><div>var customerQuery = manager.GetQuery&lt;Customer&gt;();</div><div>var orderQuery = manager.GetQuery&lt;Order&gt;();</div><div><br></div><div>var orderList = manager.GetQuery&lt;Order&gt;()</div></span></div></span></div><blockquote style="margin: 0 0 0 40px; border: n&#111;ne; padding: 0px;"><div><span ="apple-style-span"=""><div><span ="apple-style-span"=""><div>.GroupBy(it =&gt; new { it.CustomerID, it.EmployeeID })</div></span></div></span></div><div><span ="apple-style-span"=""><div><span ="apple-style-span"=""><div>.Where(g =&gt; (g.Count() &gt; 2))</div></span></div></span></div><div><span ="apple-style-span"=""><div><span ="apple-style-span"=""><div>.SelectMany(g =&gt; g, (g, order) =&gt; order);</div></span></div></span></div></blockquote><div><span ="apple-style-span"=""><div><span ="apple-style-span"=""><div><br></div><div>Int32 employeCountBefore = employeeQuery.ToList().Count;&nbsp;<span ="Apple-style-span" style=": rgb251, 251, 253; "><font color=GREEN><strong></span>// 9</strong><span ="Apple-style-span" style=": rgb251, 251, 253; "></font></span></div><div>Int32 customerCountBefore = customerQuery.ToList().Count;&nbsp;<span ="Apple-style-span" style=": rgb251, 251, 253; "><font color=GREEN><strong></span>// 93</strong><span ="Apple-style-span" style=": rgb251, 251, 253; "></font></span></div><div>Int32 orderCountBefore = orderQuery.ToList().Count;&nbsp;<span ="Apple-style-span" style=": rgb251, 251, 253; "><font color=GREEN><strong></span>// 830</strong><span ="Apple-style-span" style=": rgb251, 251, 253; "></font></span></div><div>Int32 orderListCountBefore = orderList.ToList().Count;&nbsp;<font size="3"><span ="Apple-style-span" style=": rgb251, 251, 253; "><font color=GREEN><strong></span>// First time count is 324</strong><span ="Apple-style-span" style=": rgb251, 251, 253; "></font></span></div><div></font></div><div>Employee newEmployee = AddEmployee(manager);</div><div>Customer newCustomer = AddCustomer(manager);</div><div>AddThreeOrders(manager, newEmployee, newCustomer);</div><div><br></div><div>Int32 employeCountAfter = employeeQuery.ToList().Count;&nbsp;<span ="Apple-style-span" style=": rgb251, 251, 253; "><font color=GREEN><strong></span>// 10</strong><span ="Apple-style-span" style=": rgb251, 251, 253; "></font></span></div><div>Int32 customerCountAfter = customerQuery.ToList().Count;&nbsp;<span ="Apple-style-span" style=": rgb251, 251, 253; "><font color=GREEN><strong></span>// 94</strong><span ="Apple-style-span" style=": rgb251, 251, 253; "></font></span></div><div>Int32 orderCountAfter = orderQuery.ToList().Count;&nbsp;<span ="Apple-style-span" style=": rgb251, 251, 253; "><font color=GREEN><strong></span>// 833</strong><span ="Apple-style-span" style=": rgb251, 251, 253; "></font></span></div><div>Int32 orderListCountBeforeSave = orderList.ToList().Count;&nbsp;<font size="3"><span ="Apple-style-span" style=": rgb251, 251, 253; "><font color=RED><strong></span>// Still 324 !!!</strong><span ="Apple-style-span" style=": rgb251, 251, 253; "></font></span></div><div></font></div><div><br></div><div>manager.SaveChanges();</div><div><br></div><div>Int32 orderListCountAfter = orderList.ToList().Count;&nbsp;<font size="3"><span ="Apple-style-span" style=": rgb251, 251, 253; "><font color=RED><strong></span>// Now 327 !!!</strong><span ="Apple-style-span" style=": rgb251, 251, 253; "></font></span></div><div></font></div><div><span ="Apple-style-span" style=": rgb251, 251, 253; "></font></span><span ="Apple-style-span" style=": rgb251, 251, 253; "></pre></td></tr></table></span></div></span></div><div><span ="apple-style-span"=""><br></span></div></span></div>]]>
   </description>
   <pubDate>Thu, 08 Dec 2011 13:21:40 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3134&amp;PID=12185#12185</guid>
  </item> 
 </channel>
</rss>