Quantcast
Viewing latest article 15
Browse Latest Browse All 15

Entity Framework 4 and "The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value."

You may get an error like the one above appear with a System.Data.UpdateException type.  This exception actually comes from the database, and is wrapped by the entity framework library.  The error stems from the fact that SQL Server has an entity with a not null datetime (not datetime2, but the "old-school" datetime property), and no date was supplied to the EntityObject entity.  In .NET, a default date ignores whatever SQL Server may use as a minimum, and supply a 1/1/0001 date (the value of DateTime.MinValue), a value far short of the minimum value of 1/1/1753 that SQL Server expects.

The easy way to find out is before savechanges() is called, use the watch window to examine all of the properties of the object, and look for the 1/1/0001 date.  It's usually pretty easy to find that way.

Image may be NSFW.
Clik here to view.

Viewing latest article 15
Browse Latest Browse All 15

Trending Articles