Using Code First technique with EF6
When I declare my DateTime properties like this:
Public Property StartDate As DateTime
I get this error:
System.Data.SqlClient.SqlException The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value. The statement has been terminated.
When I change my declaration to this:
Public Property StartDate As Nullable(Of DateTime)
Everything is fine.
What I don't understand is why. I have seen in other SO posts that we need to use DateTime2 with SQL, but I don't know what that means. It's not a type in code. Is it something else I should be setting up?
Am I taking a shortcut using the nullable
declaration or is that automatically changing to datetime2
during the EF processes?