-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Labels
area-model-buildingcustomer-reportedgood first issueThis issue should be relatively straightforward to fix.This issue should be relatively straightforward to fix.
Milestone
Description
If you make the default value of an enum that is mapped to the database anything other then 0 it always defaults every value saved to the default value.
Example with code: If I do default sleeping and try to set it to active and save. It will change it back to sleeping in the savechanges. But if you leave the default at 0 aka active then you can change and save as normal.
public partial class Person
{
[Key, Column(TypeName = "uniqueidentifier")]
public Guid Id { get; set; }
[Column(TypeName = "nvarchar(20)")]
public string FirstName { get; set; }
[Column(TypeName = "nvarchar(20)")]
public string LastName { get; set; }
[Column(TypeName = "int")]
public State State { get; set; }
}
public enum State
{
Active = 0,
Sleeping = 1,
}
modelBuilder.Entity<Person>(entity =>
{
entity.HasIndex(e => e.Id);
entity.Property(e => e.State)
.HasConversion<int>()
.HasDefaultValue(State.Sleeping);
});
Metadata
Metadata
Assignees
Labels
area-model-buildingcustomer-reportedgood first issueThis issue should be relatively straightforward to fix.This issue should be relatively straightforward to fix.