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: How can l use Entity Framework without App.config
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
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?
Update:
I figured out that my entity object was my dbContext (ie object context), but the auto-generated code is as follows:
'------------------------------------------------------------------------------
' <auto-generated>
' 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.
' </auto-generated>
'------------------------------------------------------------------------------
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
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.