c# - allowing a user to define a table at runtime using entity framework -


is possible dynamically build entities in entity framework 6 using code first?

is possible add properties entities @ runtime?

can entities reference each other using foreign keys?

if point me in right direction if possible, appreicate it.

edit

i have changed title reflect more of like, u can see why asked questions asked.

basically create system user can define objects(tables) want, properties on object (columns in table) references each object (relationships between tables).

now each object have id property/column. thinking of atoring these definitions in eav table structure have other ibjects defined @ design time , use linq queries on these objects. able build linq queries on these objects users want report on data. building linq queries should fine use dynamic linq (maybe)?

currently create such system have created table has many text fields, many number fields, many relationship fields , users can use ones want. 1 table , think going bite me in bottom in end, why take next level , build separate tables each object.

if knows of better way or maybe experienced similar, glad hear opinions.

ive been interested in topic since ef4. have real world solution use it. dont...

rowan miller 1 of ef developers. wrote blog on topic. dynamic model creation blog explaining how might it.

a github example buybackoff/ractor.clr see oncreating showing how.

it appear ok, but has many practical restrictions make recompile generated code or hand code more practical.

it why have not down voted others. :-)

would fun watching dig own grave teaspoon?

consider runtime implications.

  1. these approach still rely on poco type discovery. assembly can generated code on fly. , there so poco , runtime

  2. during context creation initializer runs. adjust model. auto migrate adds news properties , tables. during period of time no other contexts can instantiated. non ef access possible during automatic migration. still have logical outage.

    1. you using unknown pocos, in unknown tables. repository pattern using...

eg used type of pattern....

private irepositorybase<tpoco> instantiaterepository(basedbcontext context, type reptype, params type[] args) {    type repgenerictype = reptype.makegenerictype(args);    object repinstance = activator.createinstance(repgenerictype, context);    return (irepositorybase<tpoco>)repinstance; } 

and cast against irepository after making dynamic call factory. unable avoid dynamic calls. sticky situation.

good luck....

edit / after thought read a blog ef 7 there interesting comments rowan potentially not needing clr types. makes dynamic game bunch easier. try ef7 beta if brave.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -