I am using MVC5 with EF6 code first. I have a table with a Date(Datum) column in both tabels(Kommunication and Itemannounce) with smalldatetime type and when I try to set the date with System.DateTime.Now in the column I get the following error:
The conversion of a datetime2 data type to a smalldatetime data type resulted in an out-of-range value.The statement has been terminated.
I am aware of byte sizes and tried the following solution in my context:
protected override void OnModelCreating( DbModelBuilder modelBuilder )
{
var annons = modelBuilder.Entity<Itemannounce> ( );
annons.Property ( f => f.Datum ).HasColumnType ( "smalldatetime" );
var komm = modelBuilder.Entity<Kommunication> ( );
komm.Property ( f => f.Date ).HasColumnType ( "smalldatetime" );
base.OnModelCreating ( modelBuilder );
}
I still get same error. I tried to set the columns to NOT NULL without any luck. I am realy stuck in several days without to find a way out of this. Does anyone have a solution I have not tried?