Skip to content

Case mismatch on select/expand results in non-OData route #1515

@mitchdowd

Description

@mitchdowd

Adding OData query handling to an existing controller results in non-camelCase resulting property names when $select or $expand is used. Ideally the results should be consistent.

Assemblies affected

Currently using Microsoft.AspNetCore.OData v7.0.0

Reproduce steps

Have an existing controller with a non-OData route.

    [Route("api/values")]
    public class ValuesController : ODataController
    {
        private ValuesRepository _repo;

        public ValuesController(ValuesRepository repo)
        {
            _repo = repo;
        }

        [HttpGet]
        [EnableQuery]
        public IQueryable<Value> Get()
        {
            return _repo.Get();
        }
    }

Configure the OData EDM route, and also enable dependency injection for the existing controller route.

    public void Configure(IApplicationBuilder app)
    {
        app.UseMvc(routeBuilder =>
        {
            var modelBuilder = new ODataConventionModelBuilder();

            // EDM builder for the /odata route.
            modelBuilder.EnableLowerCamelCase()
                .EntitySet<Value>("Values")
                    .EntityType
                    .Select();

            routeBuilder.MapODataServiceRoute("ODataRoute", "odata", modelBuilder.GetEdmModel());

            // Dependency injection for the /api route.
            routeBuilder
                .Select()
                .EnableDependencyInjection();
        });
    }

Access the resulting API call from:

Expected result

I would expect consistent case-handling for both /api and /odata routes. This would allow OData query parameters to be handled on existing APIs without breaking the resulting response packet.

Actual result

While /odata/values?$select=id gives a correct response like [ { "id": 1 } ], using the /api route will give [ { "Id": 1 } ].

Additional detail

Example standalone ASP.NET Core project: ODataCamelCase.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions