Skip to content
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

Behaviour of bool fields with HasDefaultValue(true) option #15323

Closed
Linnod opened this issue Apr 11, 2019 · 2 comments
Closed

Behaviour of bool fields with HasDefaultValue(true) option #15323

Linnod opened this issue Apr 11, 2019 · 2 comments

Comments

@Linnod
Copy link

Linnod commented Apr 11, 2019

Hello!

I have an entity ClassDef with public bool IsActive { get; set; } property. I want this property to be true by default, so I have configuration like builder.Property(x => x.IsActive).HasColumnName("IsActive").HasDefaultValue(true);.

When IsActive equals FALSE, EF does not generate insert for this column (like in this issue - #6054). So database value is always TRUE.

Note, that this is correct only for this config builder.Property(x => x.IsActive).HasColumnName("IsActive").HasDefaultValue(true);. If HasDefaultValue(false), everything works fine.

Thank you!

@roji
Copy link
Member

roji commented Apr 11, 2019

The workaround mentioned in #6054 (and #7089) is still the valid way to deal with this - make your boolean property nullable. #15182 will improve this by allowing you to specify a nullable backing field instead.

Note that EF Core emits a warning for non-boolean store-generated properties which explains this (#7163). #15070 also contains some more information on alternatives recently considered by the team.

@roji roji closed this as completed Apr 11, 2019
@roji
Copy link
Member

roji commented Apr 11, 2019

Duplicate of #7089

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants