-
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
Fix the exception message for value generated key properties without a value generator #35422
Comments
@damieng While this could be seen as a regression, this is definitely an intentional change, see the test at 838ae11#diff-eab1e69f8bb78fa95c369fa2f8dea5d206eda5b3beda3b980d6366cf761346f2R197 I think that the intention of this check is to indicate that a key property that doesn't have an associated value generator shouldn't be marked as In particular, providers that don't support value generation for a particular type should override https://github.com/dotnet/efcore/blob/main/src/EFCore/Metadata/Conventions/ValueGenerationConvention.cs#L183 to avoid marking properties of that type as |
I still don't understand what should be done. |
@blogcraft Are you asking about a workaround? For that you'd need to call either |
wow, its one monster change... In my company we work always database first, so we do a fair number of reverse engineering a month... So manually changing ValueGeneratedOnAdd to ValueGeneratedNever on every decimal Pk that is used in our unit testing is... a little bit unsettling... 🥲 |
Ok! I found a way to do a work around for my unitTest Like this:
|
Previously in EF 8 if you set a property on an entity to an explicit value then it did not matter that there was no value generator available for it.
In EF9 it now throws on Add with the error message
Despite the property having a value explicitly set.
Repro
Minimal repro using InMemoryDatabase with an override to prevent a value generator from being found for integer:
Stack traces
Povider and version information
EF Core version: 9.0.0
Database provider: All
Target framework: .NET 8.0
Operating system: Windows
IDE: Rider 2404.3.3
Additional notes
I believe this was unintentionally introduced in 838ae11#diff-b9fdb780a381b36843749313b829bf2164ad758390d555891f75f05c0ce2c365R215 and was not caught in tests because all the built-in providers now provide a value generator for integers.
Specifically EF9 is now only checking entry.HasExplicitCheck after it has already decided that the property is problematic in TryFindValueGenerator.
Possible fix
It's possible that the HasExplicitCheck needs to happen before the GetContainingKeysCheck although I'm not entirely sure what that block is trying to achieve.
The text was updated successfully, but these errors were encountered: