В главном приложении я добавил это:
Код: Выделить всё
services.AddDbContext(options =>
options.UseSqlServer(
configuration.GetConnectionString("DefaultConnection"),
x => x.MigrationsAssembly("PA.Seeding")
));
Код: Выделить всё
private static ServiceProvider _serviceProvider;
public static void Init()
{
var serviceCollection = new ServiceCollection();
IConfiguration configuration;
configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetParent(AppContext.BaseDirectory).FullName)
.AddJsonFile("appsettings.json")
.Build();
serviceCollection.AddSingleton(configuration);
serviceCollection.AddSingleton();
serviceCollection.AddDbContext(options =>
options.UseSqlServer(configuration.GetConnectionString("DefaultConnection")));
_serviceProvider = serviceCollection.BuildServiceProvider();
}
public static void StartMigrations()
{
var dbContext = _serviceProvider.GetRequiredService();
dbContext.Database.Migrate();
}
Код: Выделить всё
Add-Migration NewMigration -Project PA.Seeding
Код: Выделить всё
An error occurred while accessing the Microsoft.Extensions.Hosting services. Continuing without the application service provider. Error: The entry point exited without ever building an IHost.
Unable to create an object of type 'ADbContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
Подробнее здесь: https://stackoverflow.com/questions/755 ... without-ev
Мобильная версия