Answer the question
In order to leave comments, you need to log in
Why is the seed method of the DatabaseInitializer class not called?
DB context
public class EntityDataModel : DbContext, IDataModel
{
static EntityDataModel()
{
Database.SetInitializer<EntityDataModel>(new DatabaseInitializer());
}
public DbSet<Person> Persons { get; set; }
}
public class Person
{
public int Id { get; set; }
public string Names { get; set; }
public DateTime DateOfBirth { get; set; }
public string MaritalStatus { get; set; }
public string Address { get; set; }
public string Email { get; set; }
}
internal class DatabaseInitializer : DropCreateDatabaseAlways<EntityDataModel>
{
protected override void Seed(EntityDataModel db)
{
AddPersonsToDb(ref db);
db.SaveChanges();
}
private void AddPersonsToDb(ref EntityDataModel db)
{
db.Persons.Add(
new Person
{
Names = "Лебедев Сергей Вячеславович",
DateOfBirth = new System.DateTime(1989, 11, 20),
MaritalStatus = "Не женат",
Address = "140702, г. Черемуино, ул. Голландская, дом 54, квартира 236",
Email = "[email protected]"
}
);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question