1

I have the following migration definition:

public override void Up()
        {
            AddColumn("dbo.MyTable", "MyEnum", c => c.Int(defaultValue: 0));
        }

This will add my Enum to the Sql-Table during the migration. I'm using TPH and this enum is only member of a specified type, so EF will automaticly makes it nullable.

Question:

After the migration all columns have the value of "null". Instead of 0.

I would expect that only the table entries which use this enum type will have the default value of 0.

Manuel Amstutz
  • 1,311
  • 13
  • 33
Cyril Iselin
  • 596
  • 4
  • 20
  • It's collision of tph with simple types, all columns, that is not in base class must be nullable. For future use TPT or TPC, it is easier to maintain, but harder to write light sql query. – Ivvan Jul 25 '16 at 19:45
  • And the nullable attribute has 'higher priority' than default. By default all columns are nullable, if the NOT NULLABLE is specified. So, any default value in table that is nullable, is redundant. – Ivvan Jul 25 '16 at 19:51

0 Answers0