Closed SandstromErik closed 1 day ago
Please let us know if there is an easy workaround for this. It seems that uninstalling the global tool and install a previous version explicitly does not work. It still seems to produce with the 8.0.7
version. That is dotnet tool list -g
outputs:
Package Id Version Commands Manifest
---------------------------------------------------
PS C:\Source\Utiliread\src\Catalog> dotnet tool list -g
Package Id Version Commands
----------------------------------------------------
dotnet-ef 8.0.4 dotnet-ef
yet the version number in the migration snapshot still indicates 8.0.7
.
Confirmed this is an 8.0.7 problem. TPH classes with an explicit discriminator table for all types causes the model snapshot to break. Rolling back the migration changes that were generated with 8.0.7 in git and regenerating them in 8.0.6 fixes the issue.
+1 for confirmation. System.NullReferenceException: Object reference not set to an instance of an object on TPH class - breaks on HasDiscriminator() line. Revert to 8.0.6 fixed.
Please let us know if there is an easy workaround for this. It seems that uninstalling the global tool and install a previous version explicitly does not work. It still seems to produce with the
8.0.7
version. That isdotnet tool list -g
outputs:Package Id Version Commands Manifest --------------------------------------------------- PS C:\Source\Utiliread\src\Catalog> dotnet tool list -g Package Id Version Commands ---------------------------------------------------- dotnet-ef 8.0.4 dotnet-ef
yet the version number in the migration snapshot still indicates
8.0.7
.
I had the same issue, then realized I downgraded the tool, but not the packages in the project. After doing that as well I got a working migration from 8.0.6
Leaving this here in case anyone else also didn't have their coffee yet ;)
@SandstromErik and all, my colleagues and I were investigating this issue today and by following the changes recently made to EF Core code, we've managed to overcome this quite easily - all you need to do in order to make it work with 8.0.7 is to re-name your discriminator column from "Discriminator" to something else, say "MyEntityTypeDiscriminator" - that's it, after that generated snapshot appears to be correct and looks exactly the same as with 8.0.6.
Additionally if you can't change the database schema for any reason, renaming the EF entity property and forcing the column name of "Discriminator" also works.
When I try to add a new migration which generates a new ModelSnapshot, type and name is removed from HasDescriminator in modelBuilder.Entity. I have discriminator configured in a seperate configuration file.
For example, in my configuration file I have
In version 8.0.6 this results in the following when the ModelSnapshot is generated
But now the generated snapshot looks like this, which results in a null reference exception when I try to add a new migration
Callstack:
Provider and version information
EF Core version: 8.0.7 Database provider: Microsoft.EntityFrameworkCore.SqlServer Target framework: .NET 8.0 Operating system: Windows 11 IDE: Visual Studio 2022 17.10