Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception 'The limit of '0' for Top query has been exceeded' by calling examples with parameter "top" #944

Closed
1 task done
dmvlasenk opened this issue Dec 21, 2022 · 1 comment

Comments

@dmvlasenk
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

BUG:
image

Step to reproduce:

I assume that the parameter "top" generates exceptions for all OData examples having options.Validate or [EnableQuery].

Expected Behavior

Response 200

Steps To Reproduce

No response

Exceptions (if any)

Microsoft.OData.ODataException: 'The limit of '0' for Top query has been exceeded. The value from the incoming request is '1'.'

.NET Version

net6.0

Anything else?

No response

@commonsensesoftware
Copy link
Collaborator

This is ultimately an issue with OData; however, I didn't want to just punt you over to their repo. I've updated any existing issue with comprehensive details regarding the problem in OData/AspNetCoreOData#695.

TL;DR

The crux of the problem is that Order has model bound settings applied a result of [Select] being used. This cause all other MaxTop settings to be ignored. One fix is to apply [Page(MaxTop = 42)]. That would apply to all API versions, but that might be ok. The other way is to apply it via the model builder:

builder.EntitySet<Order>("Orders").EntityType.Page(maxTopValue: 42, default);

This can easily be applied via IModelConfiguration (e.g. OrderConfiguration.cs) and can vary by API version. Model bound settings are enforced before [EnableQuery] so those settings end up being ignored.

It was pretty tedious to track down the main cause. I'll update the examples so that they at least work as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants