You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
EF Core 9 generates incorrect compiled models for negative enum sentinel values #35142
@Atulin I am not able to reproduce this. Following this change: #31923, the generated code should contain role.SetSentinelFromProviderValue(-1);. This is what I get with my attempt to reproduce this with my code below. Can you please update my code so that it reproduces the error you are seeing, or attach a new, small, runnable project or post a small, runnable code listing that reproduces what you are seeing so that we can investigate.
I don't see the enum registered with NpgSQL according to its documentation. Your code probably treats the value as a plain int because of that, while mine somehow differs because the enums are registered.
ModelEntityType.cs#L51 has the un-parenthesised -1 there. It's also the one enum that has been registered with NpgSQL according to the docs in Program.cs#L16. The unregistered enum uses very different code, however: ModelEntityType.cs#L41) uses .SetSentinelFromProviderValue(-1) instead of the sentinel: argument of .AddProperty() method.
Could it be related to NpgSQL, not to EF itself, after all?
As a side note, when the context is placed in a global namespace, it seems ef migrations add generates invalid code, with an empty using ; (20241204210350_Initial.cs#L1)
Activity
cincuranet commentedon Nov 19, 2024
The error is
CS0075: To cast a negative value, you must enclose the value in parentheses..[-]EF Core 9 generates incorrect compiled models for enum sentinel values[/-][+]EF Core 9 generates incorrect compiled models for negative enum sentinel values[/+]ajcvickers commentedon Dec 4, 2024
@Atulin I am not able to reproduce this. Following this change: #31923, the generated code should contain
role.SetSentinelFromProviderValue(-1);. This is what I get with my attempt to reproduce this with my code below. Can you please update my code so that it reproduces the error you are seeing, or attach a new, small, runnable project or post a small, runnable code listing that reproduces what you are seeing so that we can investigate.Repro code:
Atulin commentedon Dec 4, 2024
I don't see the enum registered with NpgSQL according to its documentation. Your code probably treats the value as a plain int because of that, while mine somehow differs because the enums are registered.
I will edit your code shortly, soon as I'm home.
Atulin commentedon Dec 4, 2024
@ajcvickers Here's a reproduction: https://github.com/Atulin/EfEnumTest
ModelEntityType.cs#L51 has the un-parenthesised
-1there. It's also the one enum that has been registered with NpgSQL according to the docs in Program.cs#L16. The unregistered enum uses very different code, however: ModelEntityType.cs#L41) uses.SetSentinelFromProviderValue(-1)instead of thesentinel:argument of.AddProperty()method.Could it be related to NpgSQL, not to EF itself, after all?
As a side note, when the context is placed in a global namespace, it seems
ef migrations addgenerates invalid code, with an emptyusing ;(20241204210350_Initial.cs#L1)Handle discriminators that use a value converter in the compiled model
Handle discriminators that use a value converter in the compiled model
Fix several small issues in the compiled model (dotnet#38441)