Seeding data in EF Core 2.1

Microsoft announced Entity Framework Core 2.1 RC in Build 2018. Data Seeding probably is one of the most useful features of Entity Framework and it got a nice upgrade on this version. Unlike Entity Framework 6.0, Seeding data is associated with an entity type as part of the model configuration which means Entity Framework can now track added, updated or removed data from one change to another change and generates the corresponding migration script for the changes.

Seeding data in Entity Framework Core now is as easy as:

modelBuilder.Entity<Book>().HasData(new Book {BookId = 1, Title = "Don't read this book"});

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s