I created a database schema using code-first. I created a base class for my models.
public abstract BaseObject {
public long Id {get;set;}
}
and a Country class extending my BaseObject
.
public Country : BaseObject {
public string Name {get;set;}
}
I created a Seed method in the IEntityTypeConfiguration<Country>
class for Country
public class CountryConfiguration : IEntityTypeConfiguration<Country>
{
public void Configure(EntityTypeBuilder<Country> builder)
{
builder.HasData(new Country[] {new Country {Id = 1, Name = "Canada"},
new Country{Id = 2, Name = "United-States"}
});
}
}
Later on I added IsActive
in BaseObject
and therefore added IsActive
in my seed. I know that I could have set the default value for IsActive
. But the problem is that not every object is active upon creation (Business rule mandates).
public class CountryConfiguration : IEntityTypeConfiguration<Country>
{
public void Configure(EntityTypeBuilder<Country> builder)
{
builder.HasData(new Country[] {
new Country{Id = 1, Name = "Canada", IsActive = true},
new Country{Id = 2, Name = "United-States", IsActive = true}
});
}
}
The problem is that when I run Add-Migration
the Seed for Country is not regenerated therefore when I run Update-Database
the IsActive
column is set to false automatically.
Is there any way to for EFCore to regenerate the Seed data?
EDIT: The migration containing the original Seed is one the first migration. We have currently 15 or so.
I want to know how to force a seed regeneration without having to redo any migrations.