Skip to content

Instantly share code, notes, and snippets.

@ssougnez
Last active January 14, 2026 20:34
Show Gist options
  • Select an option

  • Save ssougnez/4dada56d444fdd629710c342deb257ca to your computer and use it in GitHub Desktop.

Select an option

Save ssougnez/4dada56d444fdd629710c342deb257ca to your computer and use it in GitHub Desktop.
public class V1_0_0_InitialSetup: BaseMigration
{
private readonly AppDbContext _db;
private readonly ILogger < V1_0_0_InitialSetup > _logger;
public V1_0_0_InitialSetup(AppDbContext db, ILogger < V1_0_0_InitialSetup > logger)
{
_db = db;
_logger = logger;
}
public override Version Version => new(1, 0, 0);
public override async Task UpAsync()
{
if (FirstTime)
{
_logger.LogInformation("First run! Setting up initial data…");
_db.Products.AddRange(new Product
{
Name = "Starter Kit", Price = 49.99 m
}, new Product
{
Name = "Pro Bundle", Price = 149.99 m
});
await _db.SaveChangesAsync();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment