http://*.com/questions/18506088/entityframework-not-updating-column-with-default-value
Yes, you can't do this. You have to set the default in code. There's no real way around this.
More discussion about this here:
How to use Default column value from DataBase in Entity Framework?
有一个答案要求添加[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
加完之后,发现没有啥用
public class SomeTable
{
... [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public DateTime CreatedDate { get; set; } ...
}
结论:
这种有默认值的,只能通过自己在代码中设置对应实体的初始值,数据库的约束不起作用