Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build webapi odata model dynamically

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?

like image 735
vc 74 Avatar asked May 01 '14 07:05

vc 74


1 Answers

This sample addresses your requirement quite well: https://aspnet.codeplex.com/SourceControl/latest#Samples/WebApi/OData/v4/DynamicEdmModelCreation/

like image 130
Tan Jinfu Avatar answered Sep 29 '22 22:09

Tan Jinfu