Search code examples
asp.net-coreodata

OData/AspNetCoreOData - camelcase for entity type and entity sets


With asp.net core odata I want to ensure that all the entity types and entity sets are in lower case.

        var builder = new ODataConventionModelBuilder();
        builder.EnableLowerCamelCase();
        builder.Namespace = "myservice.odata";
        builder.ContainerName = "EntityContainer";
        builder.EnableLowerCamelCase().EntitySet<Customer>("customers")
        return builder.GetEdmModel();

In the above case the OData metadata generated has the entity type as "Customer" and entity set as "customers". I would like to have camel casing for the entity type as well. Only way I could do this was to rename the Customer class to customer.

The EnableLowerCamelCase does not work for entity types. Any suggestions on how to achieve this.

Another requirement that we have is that we want to rename the entity to another name using System.Text.Json. But looks like Asp.netcore odata does not respect that.


Solution

  • Found a way to set custom names using the Name property.

    builder.EntityType<CustomerEntity>().Name = "customer";
    builder.ComplexType<CustomerResultResponse>().Name = "customerResponse";