Print Page | Close Window

DataSourceKey question

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3151
Printed Date: 25-Mar-2025 at 9:34am


Topic: DataSourceKey question
Posted By: midnit
Subject: DataSourceKey question
Date Posted: 12-Dec-2011 at 9:46am
We have a bunch of different models and each one hits the same database so technically we only have one or two connection strings...but we currently have an EdmKey defined for each model since it includes the metadata.
 
So right now we have 27 EdmKeys in the web.config when we could just have 2 if you threw out the metadata. I have tried a few different ways of doing that with no real "success" as each "successful" solution required even more work/maintenance.
 
In trying IDataSourceKeyResolver I see that it is of no help in this area - unless there is a way to programmatically tease the metadata text out of the model but I assume that its not possible as we don't know the context?
 
Suggestions needed :)



Replies:
Posted By: kimj
Date Posted: 13-Dec-2011 at 12:11pm

You have 27 EDMXes in your application!?

Well ... the GetKey method on the resolver is called with the data source key name and extension.  The resolver can also be exported by composition context, so you could have different resolvers for different contexts.  You also know that the metadata names will always be based on the EDMX name, so for example a NorthwindIB.edmx would use a metadata string like

   metadata=res://*/NorthwindIB.csdl|res://*/NorthwindIB.ssdl|res://*/NorthwindIB.msl;

So you might be able to use the data source key + extension either as your model name, or as a key to your own dictionary of model names.
 
That's about all I can come up with.  :)
 

 



Posted By: midnit
Date Posted: 13-Dec-2011 at 12:31pm
That kinda matches what I have played with but it just feels wonky. Thank you for confirming


Posted By: rickadams
Date Posted: 14-Dec-2011 at 9:50am
we encountered a similar problem where we needed to connect to multiple databases using the same EntityModels. Our solution was to divide up the connection string and the metadata string into a DataResource Table. We looked up the metadata using the keyName and the database connection using the keyExtension. Our DataKeyResolver then concatenated the two to return the correct connection string. This means that we only have 1 metadata string per EntityModel and however many database connections we needed ( in our case 4). This also means we can also handle generating the connectionstrings for DEV, PROD and TEST databases without having an insane number of entries in the web.config ( we have a web farm of 6 servers so imaging the maintenance ). I can send you code if you wish. Hope this helps



Print Page | Close Window