I’m starting with a MVC3 application, using EF. We have a database with > 200 tables. I’m using DBFirst method.
My idea was to create a EFModel for different areas in the app, instead of getting the entire db schema into one big model. I have now run into a problem, where each model seems to want a connectionstring of its own. I have not successfully managed to change to only one common connestionstring. Should not that be possible? I’m thinking that it is the same db in the background so…
Or am I completely off here? Should I drag all tables into one big model? Or accept the fact that I will get lots of connectionstring?
Any insights?
You can’t have one EF connection string for multiple EDMX models, because the EDMX metadata is part of the EF connection string.
This shouldn’t be a problem for you, except that all of these connection strings contain an embedded DB connection string, and you might want to change that in one place instead of 5. You can, however, update the DB connection string portion at runtime using EntityConnectionStringBuilder. So you could have a “regular” (non-EF) connection string for the DB connection, then use EntityConnectionStringBuilder to substitute it into the EF connection strings when you create the context.
Off the top of my head, the code would look something like: