Entity Framework Core 3.1.8 not saving 0 to column with default value of -1

847 Views Asked by At

I have a table with one integer column that is not a primary or foreign key. It has a default value of -1.

EF auto-generated code has this setup for the table.

entity.Property(e => e.ControlFlag)
    .HasColumnName("ControlFlag")
    .HasDefaultValueSql("((-1))");

When I set ControlFlag=0 and add the row to the table by calling the EF Core SaveChanges() method, the column gets saved with -1.

If I set ControlFlag=1, the value saved in the column is 1.

Why does it not like to save 0?

0

There are 0 best solutions below