OData dynamic per-request EDM creation and endpoint routing in ASP.NET Core 3.1+

497 Views Asked by At

I need to create OData EDM model on the fly in ASP.NET Core application.

There is an example in the samples, that shows it https://github.com/OData/ODataSamples/tree/master/WebApiCore/DynamicEdmModelCreation

But it uses UseMvc, which does not work with Endpoint routing.

app.UseMvc(routeBuilder =>
            {
                routeBuilder.CustomMapODataServiceRoute("odata", "odata/{dataSource}");
            });

I want to use endpoint routing for other application functionality. I saw how OData can support endpoint routing, but only for 1 predefined model: https://devblogs.microsoft.com/odata/enabling-endpoint-routing-in-odata

app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
                endpoints.Select().Filter().OrderBy().Count().MaxTop(10);
                endpoints.MapODataRoute("odata", "odata", GetEdmModel());
            });
        
        private IEdmModel GetEdmModel()
        {
            var odataBuilder = new ODataConventionModelBuilder();
            odataBuilder.EntitySet<WeatherForecast>("WeatherForecast");

            return odataBuilder.GetEdmModel();
        } 

How can I create dynamic EDM with endpoint routing?

0

There are 0 best solutions below