Skip to content

Instantly share code, notes, and snippets.

@christiannagel
Created August 28, 2018 09:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christiannagel/de8a4407d3755c25ead37067e6717a45 to your computer and use it in GitHub Desktop.
Save christiannagel/de8a4407d3755c25ead37067e6717a45 to your computer and use it in GitHub Desktop.
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