This sample addresses your requirement quite well: https://aspnet.codeplex.com/SourceControl/latest#Samples/WebApi/OData/v4/DynamicEdmModelCreation/
Build webapi odata model dynamically
-
13-07-2023 - |
Question
All of the webapi+odata examples I've seen so far build the model in WebApiConfig.Register
using something like:
...
var modelBuilder = new ODataConventionModelBuilder();
modelBuilder.EntitySet<AClass>("SetName");
...
IEdmModel model = modelBuilder.GetEdmModel();
In my case, I would like to dynamically build the classes used in modelBuilder.EntitySet<AClass>("SetName")
at runtime and register them on the fly, the first time a request for this entity set is executed.
I've read this article where EdmEntityObject is used when no backing CLR type is available but the model is still built during the startup of the service.
Is there a way to build the model on the fly?
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow