As mentioned in this post I am loading the database data on starting the main ASP.NET project as follows:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) {
using (var serviceScope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>().CreateScope()) {
var context = serviceScope.ServiceProvider.GetService<MyContext>();
context.Database.Migrate();
context.EnsureSeedData();
}
}
But the same post also recommends manually entering data,
Please note that in general, it is recommended to apply these operations manually (rather than migrating and sowing automatically at startup) to avoid racing conditions when there are several servers and unintentional changes.
which I would prefer and use the dotnet tool as follows:
dotnet seed -c <Context> -s <SeedData>
where:
- Context is the used DbContext. The default is used if none are specified.
- SeedData is a class that contains data insertion logic.
Is it possible to create such a custom dotnet tool?
DbContext ?