MVC5, EF 6.0 Code First, SQL
I have a remotely hosted MVC5 website using an SQL database. My objective is to easily code up to copy or copy/delete certain records out of the hosted database to a local database. So I added an additional context to my development project as shown.
Public Class WebDbContext
Inherits DbContext
Public Sub New()
MyBase.New("name=WebDbConnection")
Me.Configuration.LazyLoadingEnabled = True
End Sub
Public Shared Function Create() As WebDbContext
Return New WebDbContext()
End Function
Public Property table1 As DbSet(Of Class1)
.
.
Public Property tableN As DbSet(Of ClassN)
End Class
and in web.config I added the connection string
<configuration>
.
.
<connectionStrings>
<add name="WebDbConnection" connectionString="Data Source=<ip>;Initial Catalog=<dbname>;User ID=<id>;Password=<pwd>;" providerName="System.Data.SqlClient" />
</connectionStrings>
.
.
This new context allows me to access and manipulate the website database from the development project. I will clearly need another context for the database I want to save locally, but I'm just getting started with this. I started in this direction because the Class definitions for the new context will always be up to date with the hosted database since the development project originates the Class definitions that are in the hosted database. Is there a better way to code this access to the remote database?
But my real question is: What might I expect with regard to this new WebDbContext when my next add-migration happens? Does each context create an EF add-migration requirement, or is it just the Class definitions that create the add-migration requirement and the additional context(s) won't be a problem?
Regarding access of the production database from the development project, I recognize we treat production databases differently, but this project is in early development and a quick programmatic solution is being sought. I understand at a later time when production is underway a different solution may be necessary.
Or, of course as often is the case, if there's a completely different and generally accepted way to accomplish my objective as stated at the outset, what might that be?