locked
$count not working (with VS 2010 RC)? RRS feed

Answers

  • The $count is disabled by default. You need to add "config.DataServiceBehavior.AcceptCountRequests = true" into your InitializeService method for it to work.

    Thanks,


    Vitek Karas [MSFT]
    • Marked as answer by ISTEC Thursday, February 11, 2010 3:41 PM
    Wednesday, February 10, 2010 8:19 PM
    Moderator

All replies

  • The $count is disabled by default. You need to add "config.DataServiceBehavior.AcceptCountRequests = true" into your InitializeService method for it to work.

    Thanks,


    Vitek Karas [MSFT]
    • Marked as answer by ISTEC Thursday, February 11, 2010 3:41 PM
    Wednesday, February 10, 2010 8:19 PM
    Moderator
  • Huh?!

    Why would you want to disable count requests by default?
    Thursday, February 11, 2010 11:28 AM
  • Hi,

    Security, backward compat, ...
    It's kind of the server security mind set. The service should be locked down by default (as any server product should be). We don't think that adding the one line of configuration code is such a big hurdle. And as always it's better to be safe than sorry :-)

    Thanks,
    Vitek Karas [MSFT]
    Thursday, February 11, 2010 1:15 PM
    Moderator
  • My problem seems to originate from upgrading the DS project from VS2008 or VS2010B2 (im don't remember from which).

     

     


    Initialize Service was definid as
    Public Shared Sub InitializeService(ByVal config As IDataServiceConfiguration)
    which does not support .DataServiceBehavior.AcceptCountRequests

    I created a new DS and now it works.
    BTW: VS2010 automatically includes:
    config.DataServiceBehavior.AcceptCountRequests = True
    config.DataServiceBehavior.AcceptProjectionRequests = True

     

    Thursday, February 11, 2010 3:31 PM
  • Hi,

    Yes, this behavior is intentional, we don't want to change the behavior of your project from VS 2008, that would not be very nice.

    Thanks,
    Vitek Karas [MSFT]
    Thursday, February 11, 2010 4:18 PM
    Moderator
  • ....Are you seriously suggesting that allowing a count function is a security issue?  In that case, we better not let any user select ALL the records, or they might COUNT them.

    Ludicrous.

    Dave
    Thursday, February 11, 2010 7:38 PM
  • Counting the number of records in an entity set on the service may be a very expensive operation - we want service authors who are upgrading their service to specifically opt-in to allowing this behavior. This helps to ensure that the service author understand the performance impact of allowing that query on the service.

    Shayne
    Thursday, February 11, 2010 8:47 PM
    Moderator
  • OK.  I understand your reasoning, but I completely disagree with it.

    It shouldn't be up to a DataService to decide whether to expose functions on the data or not.  Count is no more expensive that Average, Sum, or any other SET operation - there is no config setting for those functions.  Or are these to be introduced with a default of ALLOWED in the next version?!

    Not allowing COUNT by default will force many developers into retrieving all the records and counting them on the client - and badmouthing DataServices for making them do it!  Why would they even THINK there would be a permission they have to set to allow count on an entityset?!

    JM2C.
    Friday, February 12, 2010 10:18 AM
  • Hi,

    Today DataService doesn't support any other aggregation operator than count. If and when we add another one (for example Average), we will probably also add a config option and probably will disallow it by default (for the same reasons we did on count).

    Thanks,
    Vitek Karas [MSFT]
    Friday, February 12, 2010 10:22 AM
    Moderator