Possible to default DateTime field to GETDATE() with Entity Framework Migrations?

前端 未结 7 961
轻奢々
轻奢々 2020-11-28 10:20

I added EntityFramework.Migrations (Beta 1) to an existing Code-First app that is going through some changes (for both migration capabilities and more fine-tuning of the tab

7条回答
  •  清酒与你
    2020-11-28 11:09

    This is the most simple way.

    First Add DatabaseGeneratedOption.Computed DataAnnotion to your property

    and now you can modify de SqlServerMigrationSqlGenarator, override Genarate method and set the DefaultValueSql = "GETDATE()" or "GETUTCDATE()";

提交回复
热议问题