Click here to Skip to main content
15,888,113 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi how can i use more one edmx in my mvc5 project
i will want publish single project on one host with more one different databse for some customer (single project for some customer but with different databse)
but i dont know how can i switch between edmx

What I have tried:

i added some connection string in web config, and add class for check username and find database but after find user in which database i cant switch between edmx
,please help
Posted
Updated 18-Apr-20 7:22am
v2

1 solution

When you create a database context there is an overloaded constructor that lets you specify the connection name that the context uses. So have different connections to your various databases and when you create a context specify which of the connections you want to use.
 
Share this answer
 
Comments
mohamad_ali 18-Apr-20 13:42pm    
Thnx for your answer,when i add more one edmx ,The number of them is also created contex,when add overload constractor?
F-ES Sitecore 18-Apr-20 13:56pm    
If you want to use two completely different databases with different tables etc then when you create two edmx files they should be in different namespaces with different class names. If you want the same code to talk to different databases then you just add the edmx once and to change the database connection you specify it in the constructor

vat db = new DbContext("connectionName");
mohamad_ali 18-Apr-20 14:05pm    
Both of them are the same,but which senario is better?
F-ES Sitecore 18-Apr-20 14:14pm    
If you have different databases with different tables then you need two edmx files. If you have multiple databases that have the same schema then have just the one admx file and supply the connection name when you create the context objects.
mohamad_ali 18-Apr-20 14:26pm    
Thnx alot for guiding me

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900