c# - Writing code that can work with multiple database objects -
I basically have two different databases, which have different tables in them but in both of them "Table1" is the exact same structure. How can I do the above mentioned work, so I "result" from two different databases (based on "mode") without writing two different definitions for "results" "Can I specify? Store the connection string separately in your config file. You can then swap the connection string on the runtime to point to the database object in the correct database: var db = new ???; If (mode == "output") {db = new database 1 ("connection string for database 1"); } Else {db = new Database2 ("connection string for database 2"); } Var result = db. Table1.Where (a => a.Value == 1). first ();
if (mode == "PRODUCTION") {db = new database (configurationManager.ConnectionStrings [ "Production-key"]); } And {db = new database (configuration manager connection connection ["dev-key"]); }
Comments
Post a Comment