SQL column default value with Entity Framework

前端 未结 4 932
失恋的感觉
失恋的感觉 2020-12-17 10:09

I am trying to use Code-First EF6 with default SQL values.

For example, I have a \"CreatedDate\" column/property not null with a default in SQL of \"getdate()\"

4条回答
  •  醉话见心
    2020-12-17 10:44

    try with this. This code insert by default the current date

    //[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
    public DateTime Created { get; set; } = new DateTime();
    

提交回复
热议问题