-
Notifications
You must be signed in to change notification settings - Fork 474
Description
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:
- http://localhost:8001/api/values (gives correct camelCasing)
- http://localhost:8001/odata/values?$select=id (gives correct camelCasing)
- http://localhost:8001/api/values?$select=id (gives incorrect PascalCasing)
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