I have the following model entity:
public class ScheduledTask
{
public virtual int ScheduledTaskId { get; set; }
public virtual Incident TemplateIncident { get; set; }
//Some props are omitted for simplicity
[Display(Name = "Next runtime")]
[Required]
[DataType(DataType.DateTime)]
public virtual DateTime NextExecuteAfterDate { get; set; }
}
It is a part of a DataContext as:
public DbSet<ScheduledTask> ScheduledTasks { get; set; }
A UI in a solution is an MVC3 site.
Whenever a user is saving a record, a schedulable task is being saved along:
_db.Add(new ScheduledTask
{
NextExecuteAfterDate = DateTime.MinValue,
Schedule = scheduleTypeId,
TemplateIncident = incident
});
_db.SaveChanges();
As you can see, I am creating an instance of my entity class, assigning a DateTime property a minimum value and adding it to a DbContext. Then I call SaveChanges().
SaveChages() generates an
[SqlException (0x80131904): The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value.
The statement has been terminated.]
A NextExecuteAfterDate in a database is a Column of a type datetime, not null.
Where does datetime2 come from, and how can I fix the problem and get EF to add a row to a table?