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
I encountered this issue while working on my project.
It is a bit specific, and as far as I could investigate, it is related to directly to npgsql/efcore.pg than to dotnet/efcore itself.
The summarized scenario is the following:
When inserting an entity that has an enum as a property, this property has a default value that is different than the enum member that has 0 as value, it is not possible to insert the entity setting the property to the enum member that corresponds to 0.
I have encountered only one entry about this issue on stackoverflow. Also, I have look it up here on the issues, and I haven't found anything related.
See also dotnet/efcore#15070 which is specifically about warning for enums; that issue contains lots of explanations about what's going on and possible workarounds.
May I ask you where I can find about #15070, there is no link about it. Also, I couldn't find the relation between this issue and the #701. I'm not saying that this isn't a duplication, it is just seems unrelated.
I encountered this issue while working on my project.
It is a bit specific, and as far as I could investigate, it is related to directly to
npgsql/efcore.pg
than todotnet/efcore
itself.The summarized scenario is the following:
When inserting an entity that has an enum as a property, this property has a default value that is different than the enum member that has 0 as value, it is not possible to insert the entity setting the property to the enum member that corresponds to 0.
I have encountered only one entry about this issue on stackoverflow. Also, I have look it up here on the issues, and I haven't found anything related.
I've made a repo to test/reproduce this behaviour. It test against PostgreSQL and InMemory database.
https://github.com/gabrielheming/enum-default-value-error
I hadn't time to test on different databases to be sure that it is specific here, but I think it can give you everything that is necessary.
To exemplify:
Entity
Enum
DbContext
Ps.: I don't think converting to
string
adds any difference to the output, but I replicate as I had been using on my project.Execution
Expected result:
entity.MyEnum // First
Actual result:
entity.MyEnum // Second
Workaround to solve this problem
Change the MyEnum order to make sure that the default value is 0:
Set the first item of the Enum as value 1:
The text was updated successfully, but these errors were encountered: