Skip to content

Instantly share code, notes, and snippets.

@christiannagel
Created Aug 28, 2018
Embed
What would you like to do?
Shadow state with seeding data and EF Core
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
// shadow state
modelBuilder.Entity<MenuItem>().Property<DateTime>(LastUpdated);
modelBuilder.Entity<MenuItem>().Property(m => m.Text).IsRequired().HasMaxLength(40);
// use anonymous types to pass shadow state information
modelBuilder.Entity<MenuItem>().HasData(
new { MenuItemId = 1, Text = "Wiener Schnitzel mit Kartoffelsalat", MenuDate = new DateTime(2018, 8, 27), LastUpdated = DateTime.Now },
new { MenuItemId = 2, Text = "Faschierter Braten mit Karoffelpüree", MenuDate = new DateTime(2018, 8, 28), LastUpdated = DateTime.Now });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment