Skip to content

Instantly share code, notes, and snippets.

@christiannagel
Created Aug 28, 2018
Embed
What would you like to do?
Seeding Racer data with the F1Context
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Racer>().Property(r => r.Name)
.IsRequired()
.HasMaxLength(100);
modelBuilder.Entity<Racer>().Property(r => r.Team)
.IsRequired(false)
.HasMaxLength(60);
modelBuilder.Entity<Racer>().HasData(
new Racer { Id = 1, Name = "Lewis Hamilton", Team = "Mercedes" },
new Racer { Id = 2, Name = "Sebastian Vettel", Team = "Ferrari" },
new Racer { Id = 3, Name = "Kimi Räikkönen", Team = "Ferrari" },
new Racer { Id = 4, Name = "Valtteri Bottas", Team = "Mercedes" },
new Racer { Id = 5, Name = "Max Verstappen", Team = "Red Bull Racing"},
new Racer { Id = 6, Name = "Daniel Ricciardo", Team = "Red Bull Racing"}
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment