Back to Bogus

README

Examples/EFCoreSeedDb/README.md

35.6.51.2 KB
Original Source

EF Core Seed Database Example with Bogus

Requirements

  • .NET 8.0* or later
  • EF Core 8 or later

Description

The EFCoreSeedDb example is based on the EF Core Tutorial with the HasData method using Bogus.

To run the example, perform the following commands inside this EfCoreSeedDb folder:

  • dotnet restore
  • dotnet build
  • dotnet ef migrations add InitialCreate
  • dotnet ef database update
  • dotnet run

After the dotnet commands are executed above, you should have a blogging.db SQLite DB file that you can open and inspect the sample data generated from Bogus. Additionally, the dotnet run command will print out the data generated by Bogus to the console read from the blogging.db SQLite DB file.

The basic approach is to pre-generate your Bogus data in-memory, in static properties, before sending sample data to EF Core.

  • FakeData - Uses the Faker<T> approach.
  • FakeData2 - Uses the Faker facade approach.

Either approach above can be used; pick whichever fits your preference and coding style.