sql-server-rest-api icon indicating copy to clipboard operation
sql-server-rest-api copied to clipboard

Is "$count" supported?

Open Rich-AU opened this issue 4 years ago • 1 comments

When I used "$count" in the request, I got this error: {"code":-1,"message":{"lang":"en","value":"Parameter $count is not supported.","innererror":null}}

But based on this document, it seems $count is supported: https://github.com/JocaPC/sql-server-rest-api/blob/master/doc/odata.md

Just want to clarify that if "$count" is supported? Thanks.

Rich-AU avatar May 25 '20 11:05 Rich-AU

Actually it works. You just need to explicitly add a route that accepts $count: (see https://github.com/JocaPC/sql-server-rest-api/blob/master/TestApp/Controllers/RestApiController.cs#L88)

        [HttpGet("[controller]/odata/objects")]
        [HttpGet("[controller]/odata/objects/$count")]
        public async Task Objects()

Count is not one of the parameters it is specified using /$count.

You can also use $apply=aggregate(object_id with count as c) as alternative.

JocaPC avatar May 25 '20 19:05 JocaPC