'datetime2' error when using entity framework in VS 2010 .net 4.0

前端 未结 16 1234
半阙折子戏
半阙折子戏 2020-11-29 00:04

Getting this error:

System.Data.SqlClient.SqlException : The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range v

16条回答
  •  -上瘾入骨i
    2020-11-29 01:02

    I had the same issue in my ASP.Net MVC application.

    There were two model classes in my application that had DateTime properties.

    upon investigating I noticed that the DateTime property of one model was nullable i.e. to make it date of Birth optional property

    the other model had DateTime Property with Required data annotation (error occurs when saving this model)

    my app is code first so I resolved the issue by setting datatype as DateTime2

    [Column(TypeName="datetime2")] 
    

    then I ran the migration on package manager console.

提交回复
热议问题