AspNetCoreOData icon indicating copy to clipboard operation
AspNetCoreOData copied to clipboard

No way of supporting $count=true without EDM

Open michalczerwinski opened this issue 4 years ago • 5 comments

Is there any rational behind $count=true not working with [EnableQuery] attribute? I am aware that I can achieve count support using EDM approach but I would prefer sticking to [EnableQuery] for its brevity.

Can you please shed some lights why this is not possible right now? Is this something we can expect to be added in the future?

michalczerwinski avatar Sep 27 '21 17:09 michalczerwinski

@michalczerwinski Can you use the PageResult<T> in the controller when the request has $count=true query?

xuzhg avatar Sep 28 '21 16:09 xuzhg

@xuzhg: thanks for replying.

I tried this approach and failed. 2 problems:

  • when using custom PageResult I didn't manage to get $select (column selection) to work. ODataQueryOptions.ApplyTo is taking care of top,skip, etc. but no column projection
  • when returning new PageResult with NextLink and Count final response was always without those fields. I tried returning PageResult(...) and Ok(PageResult(...))

If it is any help I used Microsoft.AspNetCore.OData version 8.0.2 with .NET Core 6-rc.1

michalczerwinski avatar Sep 29 '21 09:09 michalczerwinski

@michalczerwinski Check this comment https://github.com/OData/AspNetCoreOData/issues/247#issuecomment-1068883361 I have a sample project that works https://github.com/KenitoInc/AspNetCoreOData8Net6

I hope that helps you resolve your issue

KenitoInc avatar Apr 14 '22 08:04 KenitoInc

I have a sample project that works https://github.com/KenitoInc/AspNetCoreOData8Net6

@KenitoInc the sample you provided seems to be relying on an EDM model. I think what OP wanted here was for it to work in the EDM-less flow.

julealgon avatar Apr 14 '22 18:04 julealgon

It's 2022 Is there any solution to this problem?

IvyBit avatar Aug 11 '22 13:08 IvyBit