Default Value for datetime2 field in EF6 does not works [duplicate]

I am using EF6 code first approach, wherein i have class with CreatedDate field, i have decorated it with [DefaultValue("getutcdate()")] and the Default binding has also been generated by EF, however, when i do not set any value for this field it sets as 0001-01-01 00:00:00.0000000, but since i have setuped the default value for this field, ain’t it should set the current datetime, instead of this value.

Here’s my class which has CreatedDate field:

public class User 
    public Datetime CreatedDate { get; set; }


电子邮件地址不会被公开。 必填项已用*标注