Skip to content

EnableNoDollarQueryOptions not working as expected #1518

@Gilbert32

Description

@Gilbert32

Assemblies affected
only affects ASP.NET Core OData 9.4.0
ASP.NET Core OData 9.3.2 and previous: working as expected

Describe the bug
When configuring EnableNoDollarQueryOptions=false, and adding an object of type ODataQueryOptions to an endpoint, the ODataQueryOptions.Top property is being filled and contains the top query parameter value, whether a $ was appended as a prefix to it or not.

Reproduce steps

  • Set EnableNoDollarQueryOptions=false
services.AddControllers()
                .AddOData(option =>
                {
                    option.AddRouteComponents("odata", new ODataConventionModelBuilder().GetEdmModel());
                    option.Count()
                        .Filter()
                        .OrderBy()
                        .Expand()
                        .Select()
                        .SetMaxTop(null);
                    option.EnableNoDollarQueryOptions = false;
                });
  • Add some endpoint
        [HttpGet]
        [ODataRouteComponent("Table")]
        [Route("Table")]
        [AllowAnonymous]
        public async Task<IActionResult> GetAll(ODataQueryOptions<object> options, int skip = 0, int top = 22, bool latestData = false)
        {
            return Ok(options.Top is null);
        }
  • Call the endpoint, ex. GET http://localhost:5000/api/test/Table?top=25

Expected behavior
Expected output: options.Top should be null. Under 9.4.0, the Top property is populated and reads the value from the top query parameter directly.
Before 9.4.0, options.Top is null.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions