title: Entity Framework 6.10 and database first with hard-coded connection string
body: <p>I'm trying to create libraries that will pull the connection string for entity framework from a common external source.  I made the code below after looking at the answer to this question: <a href="https://stackoverflow.com/questions/8853345/how-can-l-use-entity-framework-without-app-config">How can l use Entity Framework without App.config</a></p>
  
  <pre><code>Dim myConnectionString As String = "metadata=res://*/SoftwarePlatformModel.SoftwarePlatformModel.csdl|res://*/SoftwarePlatformModel.SoftwarePlatformModel.ssdl|res://*/SoftwarePlatformModel.SoftwarePlatformModel.msl;provider=System.Data.SqlClient;provider connection string=""data source=.\SQLEXPRESS2012;initial catalog=SoftwarePlatform;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"""
  Using db = New SoftwarePlatform.SQL.SoftwarePlatformEntities
      db.EventLogs.Add(EventLog)
      db.SaveChanges()
  End Using
  </code></pre>
  
  <p>But when I execute this code, I end up getting an error that it cannot find the connection string in the app.config file.  What am I missing?</p>
  
  <hr>
  
  <h2>Update:</h2>
  
  <p>I figured out that my entity object was my dbContext (ie object context), but the auto-generated code is as follows:</p>
  
  <pre><code>'------------------------------------------------------------------------------
  ' &lt;auto-generated&gt;
  '    This code was generated from a template.
  '
  '    Manual changes to this file may cause unexpected behavior in your application.
  '    Manual changes to this file will be overwritten if the code is regenerated.
  ' &lt;/auto-generated&gt;
  '------------------------------------------------------------------------------
  
  Imports System
  Imports System.Data.Entity
  Imports System.Data.Entity.Infrastructure
  
  Partial Public Class SoftwarePlatformEntities
      Inherits DbContext
  
      Public Sub New()
          MyBase.New("name=SoftwarePlatformEntities")
      End Sub
  
      Protected Overrides Sub OnModelCreating(modelBuilder As DbModelBuilder)
          Throw New UnintentionalCodeFirstException()
      End Sub
  
      Public Property EventLogs() As DbSet(Of EventLog)
      Public Property MonitoringAgents() As DbSet(Of MonitoringAgent)
      Public Property NetworkMonitors() As DbSet(Of NetworkMonitor)
  
  End Class
  </code></pre>
  
  <p>Still need to figure out how to either make the partial class not point to an entity container defined in app.config, create the entity container, or override the partial class.  The code above has been updated.</p>