1

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 ?

1 Answer 1

2

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();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.