The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value.
My application recently started to show this error, it is quite strange, because it worked earlier. I didn't change anything connected with DateTime in my "Word" Model. It started to happen when I added new Models to my project.
Server Error shows up when I try to Edit data. Creating and Deleting works fine.
Controller:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit([Bind(Include = "ID,UsersLanguage,OtherLanguage,Notes")] Word word, int idOfCollection)
{
if (ModelState.IsValid)
{
db.Entry(word).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index", new { idOfCollection = idOfCollection });
}
return View(word);
}
Model:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;
namespace WebLanguageTeacher.Models.MyDatabase
{
public class Word
{
public int ID { get; set; }
[MinLength(2, ErrorMessage = "Wydaje mi się, że słowo powinno mieć przynajmniej 2 litery ;)")]
[DisplayName("Język Użytkownika")]
[Required]
public string UsersLanguage { get; set; }
[MinLength(2, ErrorMessage = "Wydaje mi się, że słowo powinno mieć przynajmniej 2 litery ;)")]
[DisplayName("Inny język")]
[Required]
public string OtherLanguage { get; set; }
[DisplayName("Notatki")]
public string Notes { get; set; }
[DisplayName("Ostatnia powtórka")]
public DateTime LastReviewed { get; set; }
[DisplayName("Następna powtórka")]
public DateTime NextReview { get; set; }
[DefaultValue(0)]
[DisplayName("Przerwa między powtórkami")]
public int ReviewInterval { get; set; } /*W miejsce Difficulty*/
[DisplayName("Nazwa właściciela")]
public string OwnerName { get; set; }
public virtual Collection Collection { get; set; }
[NotMapped]
public bool ModifyReview { get; set; } /* Klient przesyła tylko za ile dni będzie następna powtórka, serwer sam generuje datę*/
public Word(){
ModifyReview = false;
}
}
}
What's wrong? I don't create any DateTime2 variables, so why my app tries to convert DateTime2 to DateTime?
I use ASP.net MVC with EntityFramework.