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. 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 ();

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:

  if (mode == "PRODUCTION") {db = new database (configurationManager.ConnectionStrings [ "Production-key"]); } And {db = new database (configuration manager connection connection ["dev-key"]); }    

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -