Question

How do I run the seed method in .NET Core?

This is my onModelBuilding method:

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    Users user = new Users
    {
        Id = Guid.NewGuid().ToString(),
        UserName = "system@admin.com",
        Email = "system@admin.com",
        FirstName = "System",
        LastName = "Administrator",
        CreatedOn = DateTime.Now,
        UpdatedOn = DateTime.Now
    };
    PasswordHasher<Users> passwordHasher = new PasswordHasher<Users>();
    user.PasswordHash = passwordHasher.HashPassword(user, "P@ssw0rd");

    modelBuilder.HasDefaultSchema(schema: DatabaseGlobals.SchemaName);
    modelBuilder.Entity<Users>().HasData(
        user    
    );
    modelBuilder.Entity<UserRoles>().HasKey(k=>new { k.UserId, k.RoleId});
    modelBuilder.Entity<Applications>();
    modelBuilder.Entity<Roles>();
    modelBuilder.Entity<EventLogs>();
    base.OnModelCreating(modelBuilder);
}

I tried to run Update-database but then it didn't do anything because my tables were already created.

My model sits in a ClassLibrary and I don't have a Startup.cs file

1
2
9/29/2018 1:00:20 PM

Accepted Answer

add-migration anyname

update-database
1
9/29/2018 6:03:40 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow