<?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 : CancellationToken and SQL LogFile</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : DevForce 2012 : CancellationToken and SQL LogFile</description>
  <pubDate>Thu, 14 May 2026 06:55:45 -700</pubDate>
  <lastBuildDate>Mon, 17 Dec 2012 02:23:35 -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=3854</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>CancellationToken and SQL LogFile : Nice, I&amp;#039;ll update as soon...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3854&amp;PID=15420#15420</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1485" rel="nofollow">cefernan</a><br /><strong>Subject:</strong> 3854<br /><strong>Posted:</strong> 17-Dec-2012 at 2:23am<br /><br />Nice, I'll update as soon as you release.]]>
   </description>
   <pubDate>Mon, 17 Dec 2012 02:23:35 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3854&amp;PID=15420#15420</guid>
  </item> 
  <item>
   <title>CancellationToken and SQL LogFile : Just a heads up. The upcoming...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3854&amp;PID=15414#15414</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1005" rel="nofollow">mgood</a><br /><strong>Subject:</strong> 3854<br /><strong>Posted:</strong> 15-Dec-2012 at 11:42am<br /><br />Just a heads up. The upcoming v2.2 release of Cocktail will have proper support for Skip and Take. Should be available on NuGet around&nbsp;Christmas.]]>
   </description>
   <pubDate>Sat, 15 Dec 2012 11:42:08 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3854&amp;PID=15414#15414</guid>
  </item> 
  <item>
   <title>CancellationToken and SQL LogFile :   Originally posted by mgoodOh,...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3854&amp;PID=15409#15409</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1485" rel="nofollow">cefernan</a><br /><strong>Subject:</strong> 3854<br /><strong>Posted:</strong> 14-Dec-2012 at 11:13am<br /><br /><table width="99%"><tr><td class="BBquote"><strong><em>Originally posted by mgood</strong></em><br /><br />Oh, I just realized what I'm missing. I skipped over your SQL. I'm just now realizing that you are using Oracle. Looks like the fact that the repository puts the take before the order by causes issues with Oracle. I wasn't aware of that. With SQL Server it doesn't matter if the Take comes before the OrderBy, but apparently it matters if you use Oracle. That's a bit concerning.&nbsp;</td></tr></table><div>Exactly!</div>]]>
   </description>
   <pubDate>Fri, 14 Dec 2012 11:13:12 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3854&amp;PID=15409#15409</guid>
  </item> 
  <item>
   <title>CancellationToken and SQL LogFile :  Based on your code, you are...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3854&amp;PID=15408#15408</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1485" rel="nofollow">cefernan</a><br /><strong>Subject:</strong> 3854<br /><strong>Posted:</strong> 14-Dec-2012 at 11:10am<br /><br /><table width="99%"><tr><td class="BBquote">Based on your code, you are filtering, then sorting and then you want to return the top x rows. Is that correct?</td></tr></table><div>Yes, but I work with Oracle Database and ROWNUM doesn't work like TOP clause in SQLServer.</div><div><br></div><div><div style=": rgb251, 251, 253;">SELECT ...</div><div style=": rgb251, 251, 253;">&nbsp; FROM (SELECT ...</div><div style=": rgb251, 251, 253;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FROM CRMALL_SILVERLIGHT."Filter" "Extent1"</div><div style=": rgb251, 251, 253;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WHERE LOWER("Extent1"."Name") LIKE 'test%'</div><div style=": rgb251, 251, 253;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ORDER BY "Extent1"."Name" ASC</div><div style=": rgb251, 251, 253;">&nbsp; &nbsp; ) &nbsp;"top"</div><div style=": rgb251, 251, 253;">&nbsp;WHERE ROWNUM &lt;= 10</div></div><div style=": rgb251, 251, 253;"><br></div><div>This query will sort&nbsp;<span style=": rgb251, 251, 253;">"Filter"&nbsp;</span>by&nbsp;<span style=": rgb251, 251, 253;">"Name" as</span>cending and then return the first ten records it encounters (the top-ten records).&nbsp;</div><div><br></div><div>If I had put your code, the sql would be:</div><div><div style=": rgb251, 251, 253;"><div>SELECT ...</div><div>&nbsp; FROM CRMALL_SILVERLIGHT."Filter" "Extent1"</div><div>&nbsp;WHERE LOWER("Extent1"."Name") LIKE 'test%'</div><div>&nbsp; &nbsp;AND ROWNUM &lt;= 10</div><div>&nbsp;ORDER BY "Extent1"."Name" ASC</div><div><br></div><div>For Oracle it means,&nbsp;<span style=": rgb255, 255, 255;">return the first ten records it encounters and then sort them by "Name".</span></div><div><span style=": rgb255, 255, 255;"><br></span></div><div><span style=": rgb255, 255, 255;">So, the results will be different, l</span><span style=": rgb255, 255, 255;">et me try to explain.&nbsp;</span><span style=": rgb255, 255, 255;">ROWNUM will be assigned&nbsp;</span><span style=": rgb255, 255, 255;">to a row after it passes the predicate phase of the query but before the query does any sorting or aggregation. So, this why we need a subquery in Oracle, first we need the sortered results and after return the first N records.&nbsp;</span></div><div><br></div><div>That's it. I don't know if I was clear.</div></div></div>]]>
   </description>
   <pubDate>Fri, 14 Dec 2012 11:10:44 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3854&amp;PID=15408#15408</guid>
  </item> 
  <item>
   <title>CancellationToken and SQL LogFile : Oh, I just realized what I&amp;#039;m...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3854&amp;PID=15407#15407</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1005" rel="nofollow">mgood</a><br /><strong>Subject:</strong> 3854<br /><strong>Posted:</strong> 14-Dec-2012 at 10:55am<br /><br />Oh, I just realized what I'm missing. I skipped over your SQL. I'm just now realizing that you are using Oracle. Looks like the fact that the repository puts the take before the order by causes issues with Oracle. I wasn't aware of that. With SQL Server it doesn't matter if the Take comes before the OrderBy, but apparently it matters if you use Oracle. That's a bit concerning.&nbsp;]]>
   </description>
   <pubDate>Fri, 14 Dec 2012 10:55:43 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3854&amp;PID=15407#15407</guid>
  </item> 
  <item>
   <title>CancellationToken and SQL LogFile : I must be missing something. Based...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3854&amp;PID=15406#15406</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1005" rel="nofollow">mgood</a><br /><strong>Subject:</strong> 3854<br /><strong>Posted:</strong> 14-Dec-2012 at 10:24am<br /><br />I must be missing something. Based on your code, you are filtering, then sorting and then you want to return the top x rows. Is that correct? So, a simple example based on my suggestion would look like this. I want to find customers in London, order them by the company name and return the top 25.&nbsp;<div><br></div><div><div>var unitOfWork = new UnitOfWork&lt;Customer&gt;(new EntityManagerProvider&lt;NorthwindIBEntities&gt;());</div><div>var customers = await unitOfWork.Entities.FindAsync(</div><div>&nbsp; &nbsp; q =&gt; q.Take(25), x =&gt; x.City == "London", q =&gt; q.OrderBy(x =&gt; x.CompanyName));</div></div><div><br></div><div><div>The above example generates the following T-SQL. That's the actual T-SQL EF 5 generates, just leaving out all the column names.</div><div><br></div><div><div>SELECT TOP (25) ...</div><div>FROM &#091;dbo&#093;.&#091;Customer&#093; AS &#091;Extent1&#093;&nbsp;</div><div>WHERE N'London' = &#091;Extent1&#093;.&#091;City&#093;&nbsp;</div><div>ORDER BY &#091;Extent1&#093;.&#091;CompanyName&#093; ASC</div></div><div><br></div><div>This query does exactly what I described above in the most optimal fashion. The WHERE clause comes first, then the ORDER BY and finally the TOP (25). Why exactly do you need a subquery?</div><div><br></div><div><br></div></div>]]>
   </description>
   <pubDate>Fri, 14 Dec 2012 10:24:56 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3854&amp;PID=15406#15406</guid>
  </item> 
  <item>
   <title>CancellationToken and SQL LogFile : Hey Marcel,I&amp;#039;d appreciate...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3854&amp;PID=15405#15405</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1485" rel="nofollow">cefernan</a><br /><strong>Subject:</strong> 3854<br /><strong>Posted:</strong> 14-Dec-2012 at 2:49am<br /><br />Hey Marcel,<div><br></div><div>I'd appreciate your advice, but in that way doesn't solve my problem. Because, it will generate a sql code doing the <i>where</i>, <i>rownum</i> and <i>order by</i> clause in the same "level". I need first a query responsible to do my <i>where</i> and <i>order by</i> clause, and after the restriction of number of rows (<i>rownum</i>). The result needs to be a query with a subquery.</div><div><br></div><div>E.G.:</div><div><div><div>SELECT ...</div><div>&nbsp; FROM (SELECT ...</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FROM CRMALL_SILVERLIGHT."Filter" "Extent1"</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WHERE LOWER("Extent1"."Name") LIKE 'test%'</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ORDER BY "Extent1"."Name" ASC</div><div>&nbsp; &nbsp; ) &nbsp;"top"</div><div>&nbsp;WHERE ROWNUM &lt;= 10</div></div></div><div><br></div><div>That why my FindAsync call is not so strange to me.</div><div><br></div><div>Regards.</div>]]>
   </description>
   <pubDate>Fri, 14 Dec 2012 02:49:08 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3854&amp;PID=15405#15405</guid>
  </item> 
  <item>
   <title>CancellationToken and SQL LogFile : Oh, yeah, sorry. Should have typed...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3854&amp;PID=15404#15404</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1005" rel="nofollow">mgood</a><br /><strong>Subject:</strong> 3854<br /><strong>Posted:</strong> 13-Dec-2012 at 7:07pm<br /><br />Oh, yeah, sorry. Should have typed it out in Visual Studio. Not sure what I was thinking. Here you go:<div><br></div><div><b style=": rgb251, 251, 253;">var result = await _unitOfWork.Entities.FindAsync(q =&gt; q.Take(PageSize)</b><b style=": rgb251, 251, 253;">,&nbsp;</b><b style=": rgb251, 251, 253;">cancellationTokenSource.Token</b><b style=": rgb251, 251, 253;">, predicate.ToPredicate&lt;T&gt;(), q =&gt; q</b><b style=": rgb251, 251, 253;">.OrderBySelector(new SortSelector(_fieldName))</b><b style=": rgb251, 251, 253;">);</b></div>]]>
   </description>
   <pubDate>Thu, 13 Dec 2012 19:07:34 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3854&amp;PID=15404#15404</guid>
  </item> 
  <item>
   <title>CancellationToken and SQL LogFile : Got it, thank you both.I&amp;#039;ll...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3854&amp;PID=15403#15403</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1485" rel="nofollow">cefernan</a><br /><strong>Subject:</strong> 3854<br /><strong>Posted:</strong> 13-Dec-2012 at 12:38pm<br /><br /><div>Got it, thank you both.</div><div><br></div><div>I'll take a look in this link Kim.</div><div><br></div><div>Marcel, your FindAsync didn't work on that way, but likewise I'll review my code. About que cancellation itself, the concepts about server can't cancel queries, and sequence # approach, I'll study the best solution to my case and try implement it without losing performance.</div>]]>
   </description>
   <pubDate>Thu, 13 Dec 2012 12:38:53 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3854&amp;PID=15403#15403</guid>
  </item> 
  <item>
   <title>CancellationToken and SQL LogFile : First off that call to FindAsync...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3854&amp;PID=15402#15402</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1005" rel="nofollow">mgood</a><br /><strong>Subject:</strong> 3854<br /><strong>Posted:</strong> 13-Dec-2012 at 11:21am<br /><br />First off that call to FindAsync looks rather strange. I think I know what you are trying to do, so it should be like this:<div><br></div><div><b style=": rgb251, 251, 253;">var result = await _unitOfWork.Entities.FindAsync(q =&gt; q.Take(PageSize), f =&gt; f.Where(predicate), q =&gt; q</b><b style=": rgb251, 251, 253;">.OrderBySelector(new SortSelector(_fieldName)),&nbsp;</b><b style=": rgb251, 251, 253;">cancellationTokenSource.Token);</b></div><div><b style=": rgb251, 251, 253;"><br></b></div><div>Second, once the server is executing a query, the server operation can't actually be cancelled. You can still cancel, but the query on the server will finish and the client then simply ignores the result and cancels the Task returned by FindAsync. When a Task gets cancelled, await throws a TaskCancelledException, so you can set a breakpoint inside of your catch to see if any of your tasks are actually getting cancelled. Keep in mind if the queries are very fast, the window to cancel is very short. Cancellation makes a lot more sense on long running queries, so the user can continue with something else, but again the server operation can't actually be cancelled. It simply lets the client continue and ignores the response from the server once it comes back.</div><div><br></div><div>A better approach here is to have a sequence #, so you know which result is the most recent and ignore any older results if they come in out of order. With the nature of asynchronous calls you have no guarantee that they finish in the same order you invoked them, so a sequence # will help the client figure out which result belongs to which&nbsp;invocation.&nbsp;</div>]]>
   </description>
   <pubDate>Thu, 13 Dec 2012 11:21:57 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3854&amp;PID=15402#15402</guid>
  </item> 
  <item>
   <title>CancellationToken and SQL LogFile :   Since the debug log on the...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3854&amp;PID=15401#15401</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=11" rel="nofollow">kimj</a><br /><strong>Subject:</strong> 3854<br /><strong>Posted:</strong> 13-Dec-2012 at 11:03am<br /><br />Since the debug log on the server contains these SQL statements, the async queries are not actually being cancelled.<div>&nbsp;</div><div>There's unfortunately only a small window in which you can truly cancel a query.&nbsp; We make one check of the cancellation token before the request is sent to the EntityServer, and once the WCF request to the server is made that can't be cancelled.&nbsp; We also don't make any attempt to contact the server via another request to cancel the query request.&nbsp; On the client, if cancellation has been requested before the server request completes we will see that and "cancel" client processing, marking the task as cancelled.&nbsp; </div><div>&nbsp;</div><div>I think that cancelling outstanding async queries may still be a good idea, but you probably need some sort of timer so you can also "coalesce" the queries.&nbsp; This is an interesting thread on StackOverflow - <a href="http://stackoverflow.com/questi&#111;ns/6293817/async-search-&#101;vent-handling" target="_blank">http://stackoverflow.com/questions/6293817/async-search-event-handling</a>&nbsp;and may give you some ideas.</div><div>&nbsp;</div><div>&nbsp;</div>]]>
   </description>
   <pubDate>Thu, 13 Dec 2012 11:03:11 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3854&amp;PID=15401#15401</guid>
  </item> 
  <item>
   <title>CancellationToken and SQL LogFile : Hello,I don&amp;#039;t know how CancellationToken...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3854&amp;PID=15400#15400</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1485" rel="nofollow">cefernan</a><br /><strong>Subject:</strong> 3854<br /><strong>Posted:</strong> 13-Dec-2012 at 4:10am<br /><br />Hello,<div><br></div><div>I don't know how CancellationToken works, so I'm doing some tests and I'm trying to cancel the execution of my queries. Actually, I have a search component that make searches while the user is typing and I wish my component cancel the previous query (if not finished yet) when the user type a new key. For example, if the user type quickly "Anna", the application should search "Anna" and not the partials "A", "An", "Ann".&nbsp;</div><div><br></div><div>In the KeyUp event, I call this method:</div><div><div>private async void Search(string textSearch)</div><div>{</div><div><span ="Apple-tab-span" style="white-space:pre">	</span>try</div><div><span ="Apple-tab-span" style="white-space:pre">	</span>{</div><div><span ="Apple-tab-span" style="white-space:pre">		</span>if (!string.IsNullOrWhiteSpace(textSearch))</div><div><span ="Apple-tab-span" style="white-space:pre">		</span>{</div><div><span ="Apple-tab-span" style="white-space:pre">			</span>foreach (var item in _cancellationTokenSourceList)</div><div><span ="Apple-tab-span" style="white-space:pre">				</span>item.Cancel();</div><div><span ="Apple-tab-span" style="white-space:pre">			</span>_cancellationTokenSourceList.Clear();</div><div><br></div><div><span ="Apple-tab-span" style="white-space:pre">			</span>CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();</div><div><span ="Apple-tab-span" style="white-space:pre">			</span>_cancellationTokenSourceList.Add(cancellationTokenSource);</div><div><br></div><div><span ="Apple-tab-span" style="white-space:pre">			</span>var predicate = PredicateBuilder.Make(typeof(T), _fieldName, FilterOperator.Contains, textSearch);</div><div><b><span ="Apple-tab-span" style="white-space:pre">			</span>var result = await _unitOfWork.Entities.FindAsync(f =&gt; f.Where(predicate).OrderBySelector(new SortSelector(_fieldName)).Take(PageSize), cancellationTokenSource.Token);</b></div><div><span ="Apple-tab-span" style="white-space:pre">			</span>ItemsSource = new BindableCollection&lt;T&gt;(result);</div><div><br></div><div><span ="Apple-tab-span" style="white-space:pre">			</span>_currentComponent.ShowPopup();</div><div><span ="Apple-tab-span" style="white-space:pre">		</span>}</div><div><span ="Apple-tab-span" style="white-space:pre">		</span>else</div><div><span ="Apple-tab-span" style="white-space:pre">		</span>{</div><div><span ="Apple-tab-span" style="white-space:pre">			</span>ItemsSource.Clear();</div><div><span ="Apple-tab-span" style="white-space:pre">			</span>_currentComponent.ClosePopup();</div><div><span ="Apple-tab-span" style="white-space:pre">		</span>}</div><div><span ="Apple-tab-span" style="white-space:pre">	</span>}</div><div><span ="Apple-tab-span" style="white-space:pre">	</span>catch (System.Exception)</div><div><span ="Apple-tab-span" style="white-space:pre">	</span>{</div><div><span ="Apple-tab-span" style="white-space:pre">		</span>//throw;</div><div><span ="Apple-tab-span" style="white-space:pre">	</span>}</div><div>}</div></div><div><br></div><div>I don't know if it's working or not, because when I take a look in the log file I can see a bunch of the same query with differents where clauses.&nbsp;</div><div>Sometimes I have exactly the sequence that the user typed:</div><div>1. WHERE (LOWER("Extent1"."Name") LIKE 'A%')</div><div><div><div>2. WHERE (LOWER("Extent1"."Name") LIKE 'An%')</div></div></div><div><div>3. WHERE (LOWER("Extent1"."Name") LIKE 'Ann%')</div></div><div><div>4. WHERE (LOWER("Extent1"."Name") LIKE 'Anna%')</div></div><div><br></div><div>Sometimes a strange sequence and repetead queries:</div><div>1. WHERE (LOWER("Extent1"."Name") LIKE 'An%')</div><div>2. WHERE (LOWER("Extent1"."Name") LIKE 'Ann%')</div><div>3. WHERE (LOWER("Extent1"."Name") LIKE 'Ann%')</div><div>4. WHERE (LOWER("Extent1"."Name") LIKE 'Anna%')</div><div><br></div><div><div>I don't know why this behavior happens and I don't know if the cancellation is happening or not because anything is mentioned in the log.</div></div><div><br></div><div>Regards.</div>]]>
   </description>
   <pubDate>Thu, 13 Dec 2012 04:10:40 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3854&amp;PID=15400#15400</guid>
  </item> 
 </channel>
</rss>