title: How to specify EntityFramework ProviderName in an Azure Function
body: <p>I'm trying to port some webjob code to the new Azure Functions. So far I've managed to import my DLL's and reference them succesfully, but when I use the connection string in my code, I get an error saying I have to add the ProviderName:</p>
  
  <blockquote>
    <p>The connection string 'ConnectionString' in the application's
    configuration file does not contain the required providerName
    attribute."</p>
  </blockquote>
  
  <p>Which is normally not a problem because in a webjob (or web app), this will be in the App or Web.config, and the connectionstring will simply be overwritten with whatever I entered in Azure.</p>
  
  <p>With Azure Functions, I don't have a web.config (Although I tried adding one to no avail), so naturally the providername is missing.</p>
  
  <p>How do I specify that?</p>
  
  <p><strong>EDIT:</strong>
  After some playing around and some helpful tips by people below, I've <em>almost</em> managed to get it working.</p>
  
  <p>What I do now is the following:</p>
  
  <pre><code>    var connString = **MY CONN STRING FROM CONFIG**; // Constring without metadata etc.
      EntityConnectionStringBuilder b = new EntityConnectionStringBuilder();
      b.Metadata = "res://*/Entities.MyDB.csdl|res://*/Entities.MyDB.ssdl|res://*/Entities.MyDB.msl";
      b.ProviderConnectionString = connString.ConnectionString;
      b.Provider = "System.Data.SqlClient";
      return new MyDB(b.ConnectionString);
  </code></pre>
  
  <p>Which gives me what I need for calling the database. I use a static method in a partial class to get an instance of the Database which runs the above code, and I decorate my MyDB Partial with  <code>[DbConfigurationType(typeof(MyDbConfiguration))]</code></p>
  
  <p>I define that configuration as:</p>
  
  <pre><code>public class MyDBConfiguration: DbConfiguration
  {
      public MyDBConfiguration()
      {
          SetProviderFactory("System.Data.EntityClient", EntityProviderFactory.Instance);
      }
  }
  </code></pre>
  
  <p>My <strong>problem remains</strong> when I want to actually use the EF Entities. Here, it will try to initialize the database type <em>using the original configuration</em>, giving me the original error once again. As per this stack trace:</p>
  
  <pre><code>at Void Initialize()
  at System.Data.Entity.Internal.EntitySetTypePair GetEntitySetAndBaseTypeForType(System.Type)
  at Void InitializeContext()
  at System.Data.Entity.Core.Objects.ObjectContext CreateObjectContextFromConnectionModel()
  at Void Initialize()
  at Boolean TryInitializeFromAppConfig(System.String, System.Data.Entity.Internal.AppConfig)
  at Void InitializeFromConnectionStringSetting(System.Configuration.ConnectionStringSettings)
  </code></pre>
  
  <p>So <strong>how do I avoid this?</strong> I guess I need a way to hook into everything and run my custom setter..</p>