0

Fairly simple question that I can't remember. We have three environments: Local machine (unique for each developer), Development, and Production. Connection Strings are in a config file (not web.config, but web.config points to the file); only one is active at a given time (the other two are commented out; all three have the same name but different values for each environment).

I'm using a rudimentary version of the ActiveRecord pattern to handle data access (i.e. static GetByProperty methods in the Linq-generated CS file). To ensure that all of us can use the Linq classes without having to muck about with the designer, all I would have to do is pass in that configuration setting with the connection string (e.g. ConfigurationManager.AppSetting["TheConnectionString"]) when I new up the DataContext, correct? I am going the approach of newing up a context per request; is there any issue (other than DRY, as I'd be repeating the whole connection string every method) I should be aware of passing the connection string in every time, or is that standard operating procedure?

1 Answer 1

1

You chose two of my least favorite things (ActiveRecord and LINQ to SQL). ;-) Regardless, you can move the code to a factory method (or similar) to avoid the DRY issue, if that particularly bugs you. You will likely have to do a small bit of refactoring and re-architecting, but you can solve that issue later.

As for changing connection strings to be environment specific, that is fairly standard operating procedure, whether you are using LINQ, DataSets, EF, or otherwise. Location of the actual persistant store is a configuration issue.

Sign up to request clarification or add additional context in comments.

2 Comments

Yeah, I would prefer NHibernate + Repository pattern, but that's "too complex" for work and introduces foreign topics. I'm lucky I got approval to use LINQ.. it was going to be Stored Procs and DataSets X-(
LINQ is a great abstraction. I love it for iterating objects, which is its strength. As a data access technology, it was largely thrown together due to the EF team "running behind" and I wish it would die a horrible death. ;-) I understand the "luck to get approval" issue, however. I am fully on the side of using configuration as much as possible, as too many people hard code (and should die a horrible death?)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.