I think there is an overload in ContextManager that allows you
to tell it to use specified value as connection string, not the connection
string’s name.
Sergey Barskiy
Principal Consultant
office: 678.405.0687 | mobile: 404.388.1899
Microsoft Worldwide Partner of the Year | Custom
Development Solutions, Technical Innovation
From: raz0rf1sh
[mailto:cslanet@lhotka.net]
Sent: Sunday, November 30, 2008 8:22 AM
To: Sergey Barskiy
Subject: [CSLA .NET] How to best change the database connection via the
ContextManager
We are currently making the switch to LinqToSql for our Dal
layer. Currently we assigned the application connection string to a
modified BusinessPrincipal object, so that we can change our database
connection on the fly. For example, we have one user interface, and the
user can select whether to work in the production or test environment.
Works great!
The problem is that the ContextManager seems to work off of the DataContext
name. So this is really limiting our flexibility, as we can't set the
database connection string through the ContextManager as it assumes the Dbml
file and the connection string have the same name.
Any ideas how to get around this?
Curelom:I found that overload as well. I would think the default should be toward a connection string and the overload should be for database name.
Maybe - but the best practice for .NET is to put the connection strings in the config file, and so the default overload is to enable that best practice.
Ok, I'm feeling a little foolish now. I've been using it like this
using
(var mgr = Csla.Data.ContextManager<HD.Library.Data.DBDataContext>.GetManager(ConfigurationManager.ConnectionStrings[
"HDConnectionString"], false))
but we can use it like this
using (var mgr = Csla.Data.ContextManager<HD.Library.Data.DBDataContext>
.GetManager("HDConnectionString"))
Copyright (c) Marimer LLC