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
Post a Comment