Hi @kobosh ,
I think there are two ways to call the seed() method.First,you could call Update-Database from the Package Manager Console.
You could refer to below article:
https://learn.microsoft.com/en-us/aspnet/web-api/overview/data/using-web-api-with-entity-framework/part-3
Second,you could call the seed method by yourself. You could change your InitializeDatabase method. Just like this:
DatabaseContext class:
public DatabaseContext() : base("DatabaseContext")
{
InitializeDatabase();
}
public DatabaseContext(string connectionString) : base(connectionString)
{
Database.Connection.ConnectionString = connectionString;
InitializeDatabase();
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
}
changed my InitializeDatabase method from:
private void InitializeDatabase()
{
Database.SetInitializer(new DatabaseInitializer());
if (!Database.Exists())
{
Database.Initialize(true);
}
}
to:
protected virtual void InitializeDatabase()
{
if (!Database.Exists())
{
Database.Initialize(true);
new DatabaseInitializer().Seed(this);
}
}
More details,you could refer to below article:
https://learn.microsoft.com/en-us/dotnet/api/system.data.entity.database.initialize?redirectedfrom=MSDN&view=entity-framework-6.2.0#overloads
Best regards,
Yijing Sun
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.