Reputation: 1237
How can I use SetInitializer
to only update the database? I don't want to drop and recreate it, because I've added only a column:
Database.SetInitializer<myDbContext>( /* Here */ );
Upvotes: 1
Views: 459
Reputation: 39946
Basically you need to use DropCreateDatabaseIfModelChanges
since your model classes (entity classes) have been changed.
You can also create your own custom initializer, if the above do not satisfy your requirements or you want to do some other process that initializes the database using the above initializer.
That should be something like this:
public class YourCustomInitializer : DropCreateDatabaseIfModelChanges<YourDBContext>
{
protected override void Seed(YourDBContext context)
{
// sample data to be written or updated to the DB
}
}
It is worth mentioning, you can simply add your new column to your entity, then use add-migration and update-database commands. You need to run these commands in the PackageManagerConsole.
Upvotes: 2