EntityFramework CodeFirst SetDefualtValue

If you see the generated migration code you will see AddColumn

AddColumn("dbo.report", "newProperty", c => c.String(nullable: false));
You can add defaultValue

AddColumn("dbo.report", "newProperty",
c => c.String(nullable: false, defaultValue: "old"));
Or add defaultValueSql

AddColumn("dbo.report", "newProperty",
c => c.String(nullable: false, defaultValueSql: "GETDATE()"));

你可能感兴趣的:(EntityFramework CodeFirst SetDefualtValue)