Reputation: 5
I'm trying to create a program that depends on Entity Framework but i need to create two types of databases Sql and Sqlite with the same DB schema in order to change to sql server if the program will work on different PCs
trying this Sol but DeDefaultConnectionFactory has been Deprecated https://github.com/narendrasinghrathore/entityMultipleDb
I don't want to create many DbContext class just one and changing the provider and the connection string.
Anybody have any idea how to do that?
Upvotes: 0
Views: 43
Reputation: 2927
You can always pass the connection string name in the constructor of the DbContext
class
// make your connectionString variable dynamic based on your connection type
if(connType == "SQL")
context = new DbContext(sQLConnectionString);
else
context = new DbContext(sQLLiteConnectionString);
For more info - https://msdn.microsoft.com/en-us/library/system.data.entity.dbcontext.dbcontext(v=vs.113).aspx#M:System.Data.Entity.DbContext.
Upvotes: 1