EF 4.1 - How to add a default on insertion for datetime column

后端 未结 6 614
野性不改
野性不改 2021-01-20 01:25

Using EF 4.1 how could I add a default value to the underlying table? In this particular case how could I set a datetime column to the equivalent of getdate every time I in

6条回答
  •  醉梦人生
    2021-01-20 02:06

    You could create a partial class for your entity, and inside the constructor set the date column to DateTime.Now. This way, every time you create an instance of your class, that field will be set to the current date "automatically".

提交回复
热议问题