Reputation: 1271
I have a dot net 4.0 DAL library project that contains three edmx files. I chose to split my data model in three files because there are many tables in my db, and from what I've read here at Stackoverflow it seemed best practice to do so.
But now I have three connection string entries in my App.config that basically uses the same database connection. Can I somehow get back to the old ado.net style with only one connection string in my config files?
Thanks, Jens
Upvotes: 3
Views: 701
Reputation: 39898
In your code you could use the EntityConnectionStringBuilder to build the three separate connection strings from a 'regular' connection string that's stored in your config file.
You would get something like:
string providerString = <load your connection string>;
// Initialize the EntityConnectionStringBuilder.
EntityConnectionStringBuilder entityBuilder =
new EntityConnectionStringBuilder();
//Set the provider name.
entityBuilder.Provider = providerName;
// Set the provider-specific connection string.
entityBuilder.ProviderConnectionString = providerString;
// Set the Metadata location.
entityBuilder.Metadata = @"res://*/AdventureWorksModel.csdl|
res://*/AdventureWorksModel.ssdl|
res://*/AdventureWorksModel.msl";
You can create three EntityConnectionStrings and change the MetaData property on each one to point to your Model.
But be aware that this would lead to a hardcoded part of your connection string in code.
Upvotes: 1