I just threw together a quick test and here's what the DbContext looks like:Note that there is only one constructor and it has no parameters, so that's the only way to create an instance. You can add a partial class and add a new constructor that takes a connection string as a parameter. That base constructor that the code above is calling accepts either the name of a connection string in the config file or an actual connection string. Your constructor can simply pass on the connection string it receives as an argument. E.g.Code:'------------------------------------------------------------------------------ ' <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 Database1Entities Inherits DbContext Public Sub New() MyBase.New("name=Database1Entities") End Sub Protected Overrides Sub OnModelCreating(modelBuilder As DbModelBuilder) Throw New UnintentionalCodeFirstException() End Sub Public Property People() As DbSet(Of Person) End ClassI'm not 100% sure but I believe that it will accept a full EF connection string or just a standard ADO.NET connection string. You can experiment a little to see what works.Code:Partial Public Class Database1Entities Public Sub New(connectionString As String) MyBase.New(connectionString) End Sub End Class




Reply With Quote
