title: How do I pass a connection string to the constructor of a database-first DBContext with Entity Framework 4.1?
body: <p>For various reasons I would like to <strong>not</strong> store the connection string for my Entity Framework DB model in one of the various .config files.  (I am using the latest and greatest DBContext API with the new Entity Framework version 4.1, .NET 4 and Visual Studio 2010 C#.)  However, the code generation template for DBContext only creates a single parameterless constructor.  (If I don't use the DBContext API, then my entity framework model has 7 different constructors to chose from, including the one I want.)</p>
  
  <p>The only way I could figure out how to do this was to directly modify the code-generation template (context.tt file) to give me the constructor I want (example code below).  This works, but it feels like I'm doing it "the hard way".  What is the correct way to get a DBContext constructor that accepts a connection string?</p>
  
  <pre><code>    public &lt;#=Code.Escape(container)#&gt;(string connectionString)
          : base(connectionString)
      {
  &lt;#
          WriteLazyLoadingEnabled(container);
  #&gt;
      }
  </code></pre>
  
  <p><em>One final note in case it might help somebody else.  Although this method works, it took me a while to realize that the "connection string" is not strictly the DB connection string, but rather the special entity framework connection string which contains the DB connection string (just like what would be stored in the app.config file).</em>  </p>