Adding int property, EF keeps making it nullable column?

.net c# entity-framework entity-framework-6

Question

I'm adding a int property called Order to an existing entity that already has records in the DB tables.

public class Page : Content
{
    // ...
    public int Order { get; set; }
    // ...

}

However, when I run "update-database", it's adding the column as nullable with a default value of null. I tried using [DefaultValue(0)], as well as setting the default in the constructor. Neither work.

How can I add a column/property to an existing set of data and have it populate as a non-null value of 0? Thanks.

1
1
7/17/2015 12:28:01 AM

Popular Answer

That's because of inheritance. Not all properties in derived types can be defined as not-nullable, because types in the upper level of hierarchy doesn't have those properties.

1
1/13/2016 10:26:51 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow