c# - How to use multiple connection string to connect different database using EntityFramework Core using the default dependency injection -


how use multiple connection string connect different database using entity framework core using default dependency injection. not able call different db context access different objects in different database under same db server using ef core , .net core.

appsettings:

"data": { "externaldbconnection": { "connectionstring": "data source=testserver;initial catalog=testdb1;integrated security=false;user id=user;password=8888;" }, "internaldbconnection": { "connectionstring": "data source=testserver;initial catalog=testdb2;integrated security=false;user id=user;password=8888;" } }

startup.cs:

    public void configureservices(iservicecollection services)     {         // add framework services.         services.addmvc();          services.addentityframework().adddbcontext<testdb1>(options => options.usesqlserver(configuration["data:externaldbconnection:connectionstring"]));          services.addentityframework().adddbcontext<testdb2>(options => options.usesqlserver(configuration["data:internaldbconnection:connectionstring"]));           automapperconfiguration.configure();     } 

db context class:

public partial class testdbcontext:dbcontext {

    public testdbcontext(dbcontextoptions<testdbcontext> options) : base(options)     {     }      protected override void onmodelcreating(modelbuilder modelbuilder)     {     }     public virtual dbset<user> users{ get; set; } 

}


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

Laravel mail error `Swift_TransportException in StreamBuffer.php line 269: Connection could not be established with host smtp.gmail.com [ #0]` -

c# SetCompatibleTextRenderingDefault must be called before the first -