Currently I achieve the above as follows.
Question: Is it the right approach in order to keep the data in the exiting tables in tact. I feel I'm doing it rather a long-winded way. Any suggestions or alternate/correct ways of doing it?
DbSet<...>
entry in myProjectContext.cs
file__EFMigrationsHistory
table from the SQL Server DbPM> add-migration mytMigration -context myProjectContext
mytMigration.cs
file except the code related to newly generated entity (model).PM> update-database -context myProjectContext
New table (corresponding to newly added entity) gets created in the exiting Db along with new __EFMigrationsHistory
table. Data in all the existing tables remains in tact.
UPDATE:
I'm following this official ASP.NET tutorial and - per their advice - have registered our context with dependency injection as follows:
Startup.cs:
public void ConfigureServices(IServiceCollection services)
{
var connection = @"Server=myDevMachine\SQL2012Instance;Database=myDb;Trusted_Connection=True;";
services.AddDbContext<ABCTestContext>(options => options.UseSqlServer(connection));
...
...
}
You should not delete anything existing. You are adding right?
Steps you should be doing:
Add-Migration looks at the existing database and model and generates a migration to update the schema.
When you run Update-Database, EF checks the migration history table and runs the migrations that were not yet executed.