c# - Entity Framework Model Builder Configuration using Reflection -


i want call below code using reflection:

modelbuilder.entity<cardpayment>().map(m =>             {                 m.mapinheritedproperties();                 m.totable("cardpayments");             }); 

i trying following:

var entitymethod = typeof(dbmodelbuilder).getmethod("entity"); entitymethod.makegenericmethod(type)           .invoke(modelbuilder, new object[] { }); 

how call "map" method parameters supplying "map" method. how can invoke "mapinheritedproperties" , "totable" methods within "map" method.

thanks

you need capture return object entitymethod.makegenericmethod(type).invoke(modelbuilder, new object[] { });, can dynamically invoke map:

var maplambda =        /* you'll need fix typing here */(m) =>        {             m.mapinheritedproperties();            m.totable("cardpayments");       };  var entitymethod = typeof(dbmodelbuilder).getmethod("entity"); var entityresult =       entitymethod.makegenericmethod(type)           .invoke(modelbuilder, new object[] { });  //invoke map entityresult.gettype().getmethod("map").invoke(entityresult, new object[]{ maplambda }); 

Comments

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -