0

I am using Entity Framework 6, and when I try to create a new record I get the following error. However, I have a default value on the column, so that when the record is created, it gets a timestamp from the DB.

The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value. The statement has been terminated.

In my table, I have a [created] column with a default constraint:

[Created] [datetime] NOT NULL CONSTRAINT [DF_Notice_Created]  DEFAULT (getdate()),

In my Class, I have a Created Property:

public System.DateTime Created { get; set; }

In my Mapping Class, I have:

this.Property(t => t.Created).HasColumnName("Created");

What configuration do I need to use, to have EF not try and create the column with a default value?

yamspog
  • 18,173
  • 17
  • 63
  • 95

1 Answers1

0

Try using DateTime? as your type (it's called a nullable type)

DrinkBird
  • 834
  • 8
  • 17