Default value of column overrides provided non-default value
See original GitHub issueI have such entity class:
public class Schedule
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public long Id { get; set; }
public ScheduleStatus Status { get; set; }
//other stuff
}
public enum ScheduleStatus
{
Test,
Pilot,
Prod
}
And DataContext is configured this way:
public class DataContext : DbContext
{
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Schedule>()
.Property(schedule => schedule.Status)
.HasConversion(new EnumToStringConverter<ScheduleStatus>())
.HasDefaultValue(ScheduleStatus.Test);
//other stuff
}
}
Then I upsert entites this way:
var scheduleStatus = CalculateStatus(someData);
serviceDataContext.Schedules.Upsert(new Schedule
{
Id = backendSchedule.Id,
Status = scheduleStatus,
})
.On(scenario => scenario.Id)
.WhenMatched((scenarioInDb, scenarioNew) =>
new Schedule
{
Status = scheduleStatus,
})
.Run();
And eventually all entites in the DB are populated with the default value of Status, regardless of what is actually assigned in the code above. I tried to use standard Add method instead of Upsert. This works correctly: when non-default value is provided it’s used.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
python - How to override a default value to a non default one
I want to override the picking_type_id value in purchase.order to be non default value. I tried doing this but it's not working:
Read more >How to Fix the "can't insert a non-default value into column ...
To solve this error, use the OVERRIDING SYSTEM VALUE option while inserting a user-specified value. Follow the steps below to fix the stated...
Read more >How to override a default value to a non default one
I want to override the picking_type_id value in purchase.order to be not required & not default value ,i tried doing this but it's...
Read more >How to use default value of data type as column default?
If a default value is defined for a particular column, it overrides any default associated with the domain. In turn, the domain default ......
Read more >8 Set Up Defaults and Overrides
The following illustrates how you set up the default values on Override Default Information. You can override the default values in columns with...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Version 2.1.1 is now live and pushed to NuGet. Should be downloadable shortly
Should I create new bug ?