-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generating new ModelSnapshot removes type and name for HasDiscriminator leading to null reference exception in 8.0.7 #34201
Comments
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
yet the version number in the migration snapshot still indicates |
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. |
I had the same issue, then realized I downgraded the tool, but not the packages in the project. 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
The text was updated successfully, but these errors were encountered: