have project have app has it's database , models, need connect database need import from. have found many articles show how set second database, not clear how use out creating model. state have been researching bit , can't seem find coherent answer.
here points
- the second database read only
- the data read context split on few tables in app
- a wish mapping have fastest import possible
- it not model read forbidden, best if dynamically typed, or created
- it seem project has 3 other dbs pull info added information
main question there appropriate workflow allow import second database app's database when second database read only?
here have far
startup.cs
public class startup { public void configureservices(iservicecollection services) { services.adddbcontext<applicationdbcontext>(options => options.usesqlserver(configuration.getconnectionstring("defaultconnection"))); services.adddbcontext<fdwdbcontext>(options => options.usesqlserver(configuration.getconnectionstring("fdwconnection"))); services.addidentity<applicationuser, identityrole>(options => { options.password.requiredigit = true; options.password.requirelowercase = true; options.password.requirenonalphanumeric = true; options.password.requireuppercase = true; options.password.requiredlength = 24; }) .addentityframeworkstores<applicationdbcontext>() .adddefaulttokenproviders(); } }
dbcontext.cs
public class fdwdbcontext : dbcontext { public fdwdbcontext(dbcontextoptions<fdwdbcontext> options) : base(options) { // second database } } public class applicationdbcontext : identitydbcontext<applicationuser> { public applicationdbcontext(dbcontextoptions<applicationdbcontext> options) : base(options) { // app's database } protected override void onmodelcreating(modelbuilder builder) { base.onmodelcreating(builder); } public dbset<applicationuser> user { get; set; } public dbset<invoice> invoice{ get; set; } public dbset<expense> expense { get; set; } }
ideas have come across
create on fly trouble here don't find information on topic. thoughts have had maybe build reference table , use map , cache (dbs don't change quickly) , "create" model that. how column name , corresponding database type dbcontext in entity framework core got thought from.
seems on kill.
reverse engineer it thought suck up, literally , have models that.
create entity framework model based on existing database in asp.net core
but here issues see, first organizationally, if db has few hundred tables? have mess of model files. know of apps have few k of tables. see swamp out real app , just.. seems on kill.
entity framework not suited scenario.
my recommendation use plain vanilla ado.net.
Comments
Post a Comment