How to fix the datetime2 out-of-range conversion error using DbContext and SetInitializer?

前端 未结 15 882
-上瘾入骨i
-上瘾入骨i 2020-12-07 19:39

I\'m using the DbContext and Code First APIs introduced with Entity Framework 4.1.

The data model uses basic data types such as string

15条回答
  •  粉色の甜心
    2020-12-07 20:05

    You can make the field nullable, if that suits your specific modeling concerns. A null date won't be coerced to a date that isn't within the range of the SQL DateTime type the way a default value would. Another option is to explicitly map to a different type, perhaps with,

    .HasColumnType("datetime2")
    

提交回复
热议问题