I am new to entity framework. Sadly My first task involves using it to create an architecture that can connect to MsSql or Mysql database just by changing the connection string. Both database will have the same schema. Can anyone guide me or point to a resource that can help me with this? Thanks.
1 Answer
Everything should be fine just make sure that you set the two connection strings in your config file.
Then make sure that you'll pass the connection string name to the DbContext in the constructor
Update :
Of course it's better to use Code Only approach
8 Comments
benin101
Thanks. So if I will keep two connection string in app.config - mssql and mysql, customer who uses mysql database will set the mysql conenctionstring and customer who uses mssql database will set the mssql connection string. So how does the code know which connections string to use? I am pretty sure I sound stupid here, but please help.
Wahid Bitar
I told u to add the two connection strings to the config considering that you'll decide which Database your system is going to use. But if you want the customer to take that choice then you may consider to make kinda wizard and let him choose one of these connection strings then store this information in the config file to use it in your DbContext constructor.
benin101
Thanks. That will work. Will I need two different models for each or just one? Will I need to make any modification to my edmx file? After going through similar questions in stackoverflow, it seemed like I had to change the ssdl or create another ssdl for each database?
Wahid Bitar
In this situation it's better to have a Code only approach.
benin101
I already have a database for the application and it is being used by a Java application also. So I guessing Code first is not an option for me?
|