Using sql date data type and EF4

James Alexander picture James Alexander · Dec 16, 2009 · Viewed 21.2k times · Source

I have a table w/ a sql date data type. When I look at the EDM markup, the storage element reflects this. The conceptual entity has a data type of DateTime (there doesn't appear to be a Date data type). When I call save changes and have a DateTime instance associated w/ the entity I want to persist, I get the following error:

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

How can I use the date data type in my schema and have EF behave? Thanks!

Answer

Craig Stuntz picture Craig Stuntz · Dec 16, 2009

Sounds like your SQL date column is non-nullable, but you haven't initialized the date on your entity before saving?