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

后端 未结 23 1352
旧时难觅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:39

    It looks like you are using entity framework. My solution was to switch all datetime columns to datetime2, and use datetime2 for any new columns, in other words make EF use datetime2 by default. Add this to the OnModelCreating method on your context:

    modelBuilder.Properties().Configure(c => c.HasColumnType("datetime2"));
    

    That will get all the DateTime and DateTime? properties on all the entities in your model.

提交回复
热议问题