Create & manage model dynamically at runtime
Hi, I heavily got stucked with making the right design decision and appreciate any valuable help:...
My company develops a web-based CMS incorporating ASP.NET MVC, Dynamic Data and Entity Framework among others. The main requirement is to enable the user to create & manage entities at runtime (e.g. product, blog, news etc.). Tables, cols, associations, constraints etc. should also be managed by the system transparently at runtime. For system-wide entities - like user, logging, media etc, - Entity Framework should be used natively.
But the most important part is scaffolding: A central, abstract scaffolding system should create the ui, making no distinction between the data source type is (EF, dynamic entities).
So my first (design) approach was:
-
Persist the schema in DB
-
Develop a LINQ-provider for read ops on my dynamic entities
-
For CUD ops, develop a custom data context, similar to EF-ObjectContext or DLinq-DataContext
-
Develop a data model provider for Dynamic Data (DD), in order to register my dynamic entities in a central scaffolding repository
-
In a generic MVC controller, fetch appropriate MetaTable via DD MetaModel and obtain corresponding data context type and query.
But today I wondered if I could realize the following:
- Use EF for managing the schema at runtime
-
NO LINQ-provider, use ELinq instead
-
NO custom data context, use ObjectContext instead
-
NO data model provider, use built-in DD-EFModelProvider instead.
-
[same as in first approach]
I also would like to use CreateQuery<T> without specifying concrete entity types - with concrete I mean Product, Blog etc. - but specifying a generic entity class instead, e.g. CreateQuery<CmsEntity>("Blog") - where CmsEntity could be derived from DBDataRecord (or not, I'm not sure yet ;-). I actually could save a huge amount of code compared to the first approach.
So, before I read tons of blogs and get lost in specs, I would like to hear from the experts if this is possible at all. I appreciate any expert hint for a possible way of doing this. I don't need details though
, I can figure it out the rest myself.
Thanks in advance
-
All Replies
No ideas?
Thank you
Murat
Hello Murat,
I am wondering what did you do in the end ?
I am trying to achieve same thing for few days now but with no success for now...
I can change ssdl,csdl and msl files at runtime in order to introduce new properties in entities, for instance, but the problem for me is object side... or as you said problem is to make new ObjectQuery<T> or CreateQuery<T> work without known or concrete type.If anyone else has idea...
- This is certainly possible. The Entity Framework has a "weakly typed" layer called EntityClient that you can talk to that looks and feels a lot like ADO.NET. If you are willing to write code against that, and use esql, rather than linq to entities, then you're good.
If you need to use code, then you'll need to engage in dynamic code generation. You're pretty much on your own there - the EF will generate the classes for you, but it would be up to you to generate the needed services. Not too difficult, though, as most services could probably be generated via a T4 template or some similar mechanism.
This posting is provided "AS IS" with no warranties, and confers no rights. the EF will generate the classes for you, but it would be up to you to generate the needed services.
You mean generation of entities with the EdmGen (EdmGen2) ?
In my case Bussines layer that should use those duynamic entities is alredy dynamic and do build linq to entities totaly based on some stored definitions and/or user input.


