Reputation:
i'm creating a web site using Asp.net core and i want to add some records to some tables at first time i run my website (on host i mean) for example category names or any .
Does any know how can i do this ?
Upvotes: 1
Views: 1181
Reputation: 1024
You can use one of the described approaches from this article.
public void Main(string[] args)
{
var host = BuildWebHost(args);
using (var scope = host.Services.CreateScope())
{
var services = scope.ServiceProvider;
var context = serviceScope.ServiceProvider.GetService<ApplicationDbContext>();
DataSeeder.SeedCountries(context);
}
host.Run();
}
Upvotes: 2