c# - Adding entities sets dynamically in dbcontext the repository layer doesnt compile -


my dbcontext code similar this:

public class mydbcontext : dbcontext, imydbcontext {    public dbset<customer> customers { get; set; }    public dbset<product> products { get; set; }   ... } 

and want add dbsets in dbcontext dinamically, code similar this:

protected override void onmodelcreating(dbmodelbuilder modelbuilder) {     var baseassemblyname = "namespace.web.model";     var assemblytype = appdomain.currentdomain.getassemblies().firstordefault(x => x.fullname.equals(baseassemblyname));      //culture class defined in assembly entity models reside     var typestoregister = assemblytype.gettypes()         .where(type => type.namespace != null && type.namespace.equals(baseassemblyname))         .where(type => type.basetype.isgenerictype && type.basetype.getgenerictypedefinition() == typeof(entitytypeconfiguration<>));      foreach (var type in typestoregister)     {         dynamic configurationinstance = activator.createinstance(type);         modelbuilder.configurations.add(configurationinstance);     } } 

but not executing, put breakpoint in beggining of method , @ point there building errors in repository layer uses example:

public icustomer get(int id) {     return db.customers.find(id); } 

what can create dinamically entities in dbcontext?

thanks!


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -