<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Entities , How many ways do I count thee ?</title><link>http://blogs.msdn.com/phaniraj/archive/2008/08/18/entities-how-many-ways-do-i-count-thee.aspx</link><description>Its a common ask that we introduce aggregating mechanisms in Data services so that one can do a Count of the number of entities present in an EntitySet easily. In this blog post , I will outline one method of implementing a “Count” method that works for</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>discount furniture &amp;raquo; Entities , How many ways do I count thee ?</title><link>http://blogs.msdn.com/phaniraj/archive/2008/08/18/entities-how-many-ways-do-i-count-thee.aspx#8875664</link><pubDate>Mon, 18 Aug 2008 03:07:52 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8875664</guid><dc:creator>discount furniture &amp;raquo; Entities , How many ways do I count thee ?</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://informationsfunnywallpaper.cn/?p=954"&gt;http://informationsfunnywallpaper.cn/?p=954&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: Entities , How many ways do I count thee ?</title><link>http://blogs.msdn.com/phaniraj/archive/2008/08/18/entities-how-many-ways-do-i-count-thee.aspx#8878022</link><pubDate>Tue, 19 Aug 2008 09:48:39 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8878022</guid><dc:creator>JB</dc:creator><description>&lt;P&gt;Great solution if all you want is the complete count of an entityset. &lt;/P&gt;
&lt;P&gt;But by not implementing the 'Count()' method of IQueriable in DataServices we are going to be very limited in uses for this technology. The benefits of using paging or virtual lists &amp;nbsp;will be diminished because you will need to return all the results to the client to count the possible rows and discard the rows not visible in the current view. &lt;/P&gt;</description></item><item><title>re: Entities , How many ways do I count thee ?</title><link>http://blogs.msdn.com/phaniraj/archive/2008/08/18/entities-how-many-ways-do-i-count-thee.aspx#8879133</link><pubDate>Tue, 19 Aug 2008 19:23:37 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8879133</guid><dc:creator>PhaniRajuYN</dc:creator><description>&lt;P&gt;Hi JB,&lt;/P&gt;
&lt;P&gt;You are partially right , the ServiceOp does not take expressions as input , which means that this URI is invalid&lt;/P&gt;
&lt;P&gt;/Count?entitySetName='Customers(1)/Orders'&lt;/P&gt;
&lt;P&gt;You can only count top level entity sets with this function.&lt;/P&gt;
&lt;P&gt;Now , about the second part :&lt;/P&gt;
&lt;P&gt;"The benefits of using paging or virtual lists &amp;nbsp;will be diminished because you will need to return all the results to the client to count the possible rows and discard the rows not visible in the current view. "&lt;/P&gt;
&lt;P&gt;I dont fully understand what this means .&lt;/P&gt;
&lt;P&gt;The support for server-side paging has existed since the CTP days in the form of $top and $skip.&lt;/P&gt;
&lt;P&gt;If you specify the $top and $skip options why would anything other than the current page of results be returned ? Can you please clarify ?&lt;/P&gt;
&lt;P&gt;This is how the paging functions are used in the URI :&lt;/P&gt;
&lt;P&gt;Get First 10 Rows&lt;/P&gt;
&lt;P&gt;/Customers?$top=10&lt;/P&gt;
&lt;P&gt;Get 2nd page of 10 rows&lt;/P&gt;
&lt;P&gt;/Customers?$skip=10&amp;amp;$top=10&lt;/P&gt;
&lt;P&gt;The general pattern is :&lt;/P&gt;
&lt;P&gt;/&amp;lt;EntitySetName&amp;gt;?$skip=(CurrentPageIndex*PageSize)&amp;amp;$top=PageSize&lt;/P&gt;</description></item><item><title>re: Entities , How many ways do I count thee ?</title><link>http://blogs.msdn.com/phaniraj/archive/2008/08/18/entities-how-many-ways-do-i-count-thee.aspx#8897078</link><pubDate>Tue, 26 Aug 2008 14:49:43 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8897078</guid><dc:creator>PR</dc:creator><description>&lt;P&gt;While not related to the intention of this post, &amp;nbsp;I am wondering if the client code would remain the same if the service operation was attributed as WebInvoke (see below). &amp;nbsp;I tried this and got an error 'method not allowed'. &amp;nbsp; Let me know. thanks.&lt;/P&gt;
&lt;P&gt;// SERVER &lt;/P&gt;
&lt;P&gt;[WebInvoke]&lt;/P&gt;
&lt;P&gt;public long Count(string entitySetName) {&lt;/P&gt;
&lt;P&gt;//Implementation goes here&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;//CLIENT&lt;/P&gt;
&lt;P&gt;//Call the ServiceOperation on the server side passing the entitySetName as a parameter&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;var results = context.Execute&amp;lt;long&amp;gt;(new Uri(String.Format("Count?entitySetName='{0}'", entitySetName), UriKind.RelativeOrAbsolute) &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;);&lt;/P&gt;</description></item><item><title>re: Entities , How many ways do I count thee ?</title><link>http://blogs.msdn.com/phaniraj/archive/2008/08/18/entities-how-many-ways-do-i-count-thee.aspx#8922529</link><pubDate>Wed, 03 Sep 2008 22:15:20 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8922529</guid><dc:creator>Jabe</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;what JB (my initials are the same, btw) probably means:&lt;/p&gt;
&lt;p&gt;How would you calculate how many pages to show when doing pagination AND filtering.&lt;/p&gt;
&lt;p&gt;Just a simple &amp;quot;Displaying page 1 of 20 (filtered)&amp;quot; message.&lt;/p&gt;
&lt;p&gt;Same with virtual lists, you need the row count of your query to get the scrollbar right.&lt;/p&gt;</description></item><item><title>re: Entities , How many ways do I count thee ?</title><link>http://blogs.msdn.com/phaniraj/archive/2008/08/18/entities-how-many-ways-do-i-count-thee.aspx#8923596</link><pubDate>Thu, 04 Sep 2008 07:57:12 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8923596</guid><dc:creator>PhaniRajuYN</dc:creator><description>&lt;p&gt;Jabe,&lt;/p&gt;
&lt;p&gt; Thanks for clarifying that .&lt;/p&gt;
&lt;p&gt; If you are dealing with virtual rows , then there should be some actual data in the store for the same. Retrieving a count for the virtual rows in this way without downloading all the rows would be easy if you can offload the counting of the rows to the DataProvider.&lt;/p&gt;
&lt;p&gt;When dealing with Sql Server , you can write a stored procedure and call it from the Service Operation .&lt;/p&gt;
&lt;p&gt;or when dealing with a CLR backed data source , you can have a method on the data provider which can be accessed in the ServiceOperation via the this.CurrentDataSource property and return the virtual count for the entity set .&lt;/p&gt;
&lt;p&gt;I would think that this would be easy to implement and gives you a lot of flexibility in customizing your counting logic.&lt;/p&gt;
&lt;p&gt;Does that help ?&lt;/p&gt;
</description></item><item><title>re: Entities , How many ways do I count thee ?</title><link>http://blogs.msdn.com/phaniraj/archive/2008/08/18/entities-how-many-ways-do-i-count-thee.aspx#8923901</link><pubDate>Thu, 04 Sep 2008 10:38:37 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8923901</guid><dc:creator>Jabe</dc:creator><description>&lt;P&gt;Hi, thanks for your answer.&lt;/P&gt;
&lt;P&gt;In my case I'm using ExtJS to query my REST interface. Now, ExtJS more or less expects a total property in the JSON response. So the perfect solution for my problem would be to extend the returned JSON object and add a count.&lt;/P&gt;
&lt;P&gt;However I am not sure if thats even possible.&lt;/P&gt;</description></item><item><title>re: Entities , How many ways do I count thee ?</title><link>http://blogs.msdn.com/phaniraj/archive/2008/08/18/entities-how-many-ways-do-i-count-thee.aspx#8978175</link><pubDate>Mon, 06 Oct 2008 20:35:16 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8978175</guid><dc:creator>Chris</dc:creator><description>&lt;P&gt;Thanks for the code,&lt;/P&gt;
&lt;P&gt;When I copy and paste your Client side code, I get a compile error on the line "long count = results.First&amp;lt;long&amp;gt;();" saying:&lt;/P&gt;
&lt;P&gt;'System.Collections.Generic.IEnumerable&amp;lt;long&amp;gt;' does not contain a definition for 'First' and no extension method 'First' accepting a first argument of type 'System.Collections.Generic.IEnumerable&amp;lt;long&amp;gt;' could be found (are you missing a using directive or an assembly reference?)&lt;/P&gt;
&lt;P&gt;I have both of these libraries included:&lt;/P&gt;
&lt;P&gt;using System.Collections.Generic;&lt;/P&gt;
&lt;P&gt;using System.Data.Services.Client;&lt;/P&gt;
&lt;P&gt;What's missing?&lt;/P&gt;</description></item></channel></rss>