Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using sql date data type and EF4

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!

like image 902
James Alexander Avatar asked Dec 16 '09 17:12

James Alexander


People also ask

What is difference between datetime and DateTime2 in SQL Server?

Microsoft recommends using DateTime2 instead of DateTime as it is more portable and provides more seconds precision. Also, DateTime2 has a larger date range and optional user-defined seconds precision with higher accuracy. Datetime2 aligns with SQL standards.

How to format Sql TimeStamp?

SQL Date Data Types DATETIME - format: YYYY-MM-DD HH:MI:SS. TIMESTAMP - format: YYYY-MM-DD HH:MI:SS. YEAR - format YYYY or YY.

When converting from a varchar data type to a datetime data type the value is out of range?

The conversion of a varchar data type to a datetime data type resulted in an out-of-range value. You need separators for the date like a “/”, a “.” or a “-“. We use substring to concatenate the “-” to use an acceptable date format and then we use the CONVERT function to convert the characters to sql date.


1 Answers

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

like image 110
Craig Stuntz Avatar answered Sep 27 '22 23:09

Craig Stuntz