question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Default value of column overrides provided non-default value

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
artiomchicommented, May 21, 2019

Version 2.1.1 is now live and pushed to NuGet. Should be downloadable shortly

0reactions
bhavink25commented, May 31, 2019

Should I create new bug ?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found