New Posts New Posts RSS Feed: DataSourceKey question
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

DataSourceKey question

 Post Reply Post Reply
Author
midnit View Drop Down
Senior Member
Senior Member
Avatar

Joined: 22-Jun-2009
Location: Charlotte
Posts: 112
Post Options Post Options   Quote midnit Quote  Post ReplyReply Direct Link To This Post Topic: DataSourceKey question
    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 :)
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post 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.  :)
 

 

Back to Top
midnit View Drop Down
Senior Member
Senior Member
Avatar

Joined: 22-Jun-2009
Location: Charlotte
Posts: 112
Post Options Post Options   Quote midnit Quote  Post ReplyReply Direct Link To This Post Posted: 13-Dec-2011 at 12:31pm
That kinda matches what I have played with but it just feels wonky. Thank you for confirming
Back to Top
rickadams View Drop Down
Newbie
Newbie
Avatar

Joined: 04-Mar-2011
Posts: 12
Post Options Post Options   Quote rickadams Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down