Add some data to table on first run in asp.net core(Fill database)

Radman :

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 ?

OxQ :

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();
}

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=398068&siteId=1