I’ve added Entity Framework to an existing project with existing tables. These tables contains a couple of uniqueidentifier columns that is NULL. When I load data from these my model-property is also null and not Guid.Empty. I’ve tried setting the default value using both the constructor and
AlterColumn("tblItems", "ThreadRoot", c => c.Guid(nullable: true, defaultValue: Guid.Empty));
but it still return null.
How can I achieve this?
That’s because the data already present will contain
null, because they were stored before you issued theAlterColumnmethod. The default value will be written when a new record is inserted, when the appropriate column is not set.