Different Connection Strings with Entity Framework based on Context

前端 未结 2 1876
暖寄归人
暖寄归人 2021-01-01 07:21

I have a web forms application that uses entity framework, the application is deployed on a development box, my local machine and a production box. Each of these have differ

相关标签:
2条回答
  • 2021-01-01 07:50

    We have something vaguely similar, I created a class to wrap the EntityContext object, which sets the connection string appropriately - you'd need something similar, based on how you set your connection string:

    Public Class MyEntityModel
    
        Private _dataContext As Entities
    
        Public Sub New()
    
            Dim entityBuilder As New EntityConnectionStringBuilder()
    
            entityBuilder.ProviderConnectionString = MyApplicationConnectionString
    
            entityBuilder.Metadata = "res://*/"
    
            entityBuilder.Provider = "System.Data.SqlClient"
    
            _dataContext = New Entities(entityBuilder.ConnectionString)
    
        End Sub
    
        Public Function DataContext() As Entities
            Return _dataContext
        End Function
    
    End Class
    
    0 讨论(0)
  • 2021-01-01 07:54

    FYI You can use config transformations now in VS 2010: http://msdn.microsoft.com/en-us/vstudio/Video/ff801895

    0 讨论(0)
提交回复
热议问题