Support for a Single Project with Multiple Provider Migrations - Edge Case/Issue/Request
Summary: Separate class library projects are required to support multiple database providers. It would be nice if one method in the IMigrator (that seems broken) could be fixed to allow placement of multiple provider migrations in a single project, but under different namespace folders (see example code).
public virtual void Migrate(string? targetMigration = null)
This project attempts to illustrate an edge case that makes separate class library projects a requirement when multiple database providers are used. There seems to be an error in an internal Migrate method that ignores any target migration id when supplied. Noting that this is all undocumented and not supported. It would be very nice to have support for the scenario described.
Code to retrieve the IMigrator implementation. Similar to EF source code that does the same thing.
private static IMigrator GetMigratorService(DbContext dbContext)
{
DatabaseFacade databaseFacade = dbContext.Database;
IInfrastructure<IServiceProvider> serviceProvider = databaseFacade;
IMigrator service = serviceProvider.Instance.GetService<IMigrator>();
return service ?? throw new InvalidOperationException(RelationalStrings.RelationalNotInUse);
}
Make a public method to allow running a migration by a specific target migration id. Or, fix the internal method that already has this parameter but seems not to work as expected. Based on the method name and parameter name.
Provider and version information
EF Core version: 8.0.6 or 8.0.7
Entity Framework Core .NET Command-line Tools: 8.0.6
Database provider: Microsoft.EntityFrameworkCore.SqlServer or Microsoft.Data.Sqlite
Target framework: .NET 8.0
Operating system: Windows 11 Pro
IDE: Visual Studio 2022 17.10.3
Support for a Single Project with Multiple Provider Migrations - Edge Case/Issue/Request
Sample project to reproduce on my repo here: Single Project with Multiple Provider Migrations Issue - Entity Framework
Permalink to dotnet EF source code method not working as expected: efcore > src > EFCore.Relational > Migrations > Internal > Migrator.cs
This project attempts to illustrate an edge case that makes separate class library projects a requirement when multiple database providers are used. There seems to be an error in an internal Migrate method that ignores any target migration id when supplied. Noting that this is all undocumented and not supported. It would be very nice to have support for the scenario described.
Code to retrieve the IMigrator implementation. Similar to EF source code that does the same thing.
Documentation for the supported feature can be found here, Microsoft - Migrations with Multiple Providers, and here, Microsoft - Using a Separate Migrations Project.
Proposed solution:
Make a public method to allow running a migration by a specific target migration id. Or, fix the internal method that already has this parameter but seems not to work as expected. Based on the method name and parameter name.
Provider and version information
EF Core version: 8.0.6 or 8.0.7 Entity Framework Core .NET Command-line Tools: 8.0.6 Database provider: Microsoft.EntityFrameworkCore.SqlServer or Microsoft.Data.Sqlite Target framework: .NET 8.0 Operating system: Windows 11 Pro IDE: Visual Studio 2022 17.10.3