The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value

后端 未结 23 1401
旧时难觅i
旧时难觅i 2020-11-28 20:19

I have the following code in my HomeController:

public ActionResult Edit(int id)
{
    var ArticleToEdit = (from m in _db.ArticleSet where m.storyId == id se         


        
23条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-28 20:43

    This is a common error people face when using Entity Framework. This occurs when the entity associated with the table being saved has a mandatory datetime field and you do not set it with some value.

    The default datetime object is created with a value of 01/01/1000 and will be used in place of null. This will be sent to the datetime column which can hold date values from 1753-01-01 00:00:00 onwards, but not before, leading to the out-of-range exception.

    This error can be resolved by either modifying the database field to accept null or by initializing the field with a value.

提交回复
热议问题