Open dashiell-zhang opened 23 hours ago
options.UseNpgsql(dataSourceBuilder.Build());
I found that even if I remove the MigrationsAssembly setting, the same error will occur.
Remaining arguments: . Finding DbContext classes... Finding IDesignTimeDbContextFactory implementations... Finding DbContext classes in the project...
The main problem is that the DatabaseContext in the Repository in the Repository.Tool dependent project cannot be found in EF 9.0, but it can be found in EF 8.0.
After switching the database driver to Microsoft.EntityFrameworkCore.SqlServer and using Microsoft.EntityFrameworkCore.Relational 9.0.0 official version and Microsoft.EntityFrameworkCore.Tools 9.0.0 official version, the problem no longer exists. Migration files can be generated normally. Therefore, it is inferred that the problem should be caused by Npgsql.EntityFrameworkCore.PostgreSQL. I am using
Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.0-rc.2"
Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.0-rc.2.24474.1"
Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.0-rc.2.24474.1"
Originally opened in EF as https://github.com/dotnet/efcore/issues/35103
My DatabaseContext is placed in the Repository class library. I created a Repository.Tool project specifically to perform EF migration operations. At the same time, I set the Migrations folder in the migration process in Repository.Tool. I have always done this in .net 6.0 - 8.0. Today, after upgrading to .net 9.0 and pairing it with Npgsql.EntityFrameworkCore.PostgreSQL 9.0.0-rc.2, I found that the following problem occurred when performing EF migration. I withdrew .net 8.0 and did the same operation.
PM> Add-Migration Init Build started... Build succeeded. No DbContext was found in assembly 'Repository.Tool'. Ensure that you're using the correct assembly and that the type is neither abstract nor generic. PM>
Sample project https://github.com/dashiell-zhang/NetEngine.git