Different connection strings

Jul 21, 2010 at 10:13 PM

I have an application that hits 2 different databases, one for US and one for Europe. I would like to be able to set the connection string to the one or the other as the application starts up. All the connections are hard coded in the generated classes such as below

using (var ctx = Csla.Data.ObjectContextManager.GetManager("SOXEntities"))

Can we set it up to allow us to change the connection string. Maybe something like this

public MyClassList() {

ApplicationContext.GlobalContext.Add("SOXConnection", "SOXEntities")

 }

using (var ctx = Csla.Data.ObjectContextManager.GetManager(ApplicationContext.GlobalContext["SOXConnection"))

then I could just change "SOXConnection" to something like "SOXEntitiesUSA" or "SOXEntitiesEU" and I wouldn't have to muck with the generated code.

or possibly some other way.

Developer
Jul 22, 2010 at 1:14 AM

Hi brenchId,

Thank you for using our CSLA Extension.

I'd just like to point out the fact that once you add the CslaExtension.template to your project, there is nothing keeping you from actually modifying the template to suit your needs better. It would be quite simple to edit the T4 template to generate those line of codes for you for each generated class.

Of course I understand that having to manually edit the T4 template can be tedious, and this is exactly why we are trying to think of a way to let users customize the template, but we are still far from our goal. In the meantime, you could always create your own Visual Studio Item Template from your modified T4 template and insert it instead of ours. You'd still benefit from the EF Extenstion itself.

Don't hesitate to give us such comments and ideas on possible improvements.

Luc

Coordinator
Jul 22, 2010 at 6:28 AM
I'll add this request to our to-do list. This problem can be solved by adding a new class Database that has a property ConnectionString, which can be set at runtime. The template should use that string instead of hard coded database name.
Coordinator
Jul 22, 2010 at 6:29 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.