Repository navigation
Closed
Labels
Milestone
Description
The page documents how to create a project using a single DbContext with multiple providers using external migration assemblies, however this doesn't seem to work.
Providing the migrations assembly on creation of a migration:
dotnet ef migrations add InitialCreate --project Data\App.Data.Migrations.Sqlite --startup-project Data\App.Data --context AppContextYields an error:
"Could not load assembly 'App.Data.Migrations.Sqlite'. Ensure it is referenced by the startup project 'App.Data'."
// some factory setup method
switch (_storageProviderConfiguration.Provider.ToLower())
{
case "sqlite":
optionsBuilder.UseSqlite(connectionString, x => x.MigrationsAssembly("App.Data.Migrations.Sqlite"));
break;
case "sqlserver":
optionsBuilder.UseSqlServer(connectionString, x => x.MigrationsAssembly("App.Data.Migrations.SqlServer"));
break;
case "postgresql":
optionsBuilder.UseNpgsql(connectionString, x => x.MigrationsAssembly("App.Data.Migrations.Postgresql"));
break;
case "mysql":
var serverVersion = ServerVersion.AutoDetect(connectionString);
optionsBuilder.UseMySql(connectionString, serverVersion, x => x.MigrationsAssembly("App.Data.Migrations.MySql"));
break;
default:
throw new NotSupportedException($"Unsupported database provider '{_storageProviderConfiguration.Provider}'");
}The assembly hosting the context doesn't have references to the migration assemblies, and can't because it would create a circular dependency. The migrations assemblies require a reference to the context in order to function.
Am I missing something here?
Document Details
⚠ Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.
- ID: 7b011c7a-3534-78e3-b491-addd96fb5ba1
- Version Independent ID: 371826c5-3ef2-4eef-32e9-d55c777cd9d3
- Content: Migrations with Multiple Providers - EF Core
- Content Source: entity-framework/core/managing-schemas/migrations/providers.md
- Product: entity-framework
- Technology: entity-framework-core
- GitHub Login: @bricelam
- Microsoft Alias: avickers
Reacted by Marek Chovanec
Activity
replaysMike commentedon Apr 10, 2023
A temporary workaround could be to copy the migration assembly dll's to the App.Data output folder after build, but that's not ideal at all. A better solution would be giving it a way to resolve those assemblies.
Looking at the Two project or Three project examples I'm not quite sure how it could work with no reference to the assemblies.
The Three Project example looked more promising, since it has a reference to the migrations assemblies as well as the DbContext. However, the DbContext cannot be found.
No DbContext named 'AppContext' was found.ajcvickers commentedon Apr 17, 2023
Note for triage: it would be really useful to have an actual sample solution for this so that I'm not left trying to stitch things together for multiple places.
mKenfenheuer commentedon Jul 17, 2024
I have had the same problem, turned out after removing the dot in the assembly name it worked!
Before
KCloud.Migrations.SqliteAfter
SqliteMigrationsNow it works.
mKenfenheuer commentedon Jul 17, 2024
@ajcvickers Just checked with the sample code TwoProjectMigrations.
If you take the project as is, it works just fine.
If you add a dot somewhere in the project names (e.g. Sqlite.Migrations or SqlServer.Migrations) it will not work anymore.
Please refer to the patch for further details: patch.txt
Expand and clarify migrations guidance. (dotnet#5445)