0

I've been looking for a solution to this for hours. The problem I have having is that I have an SQL table which is storing dates as datetime DATATYPES, but when I try to pass a DateTime field to this table with Entity framework It's of datetime2 DATATYPE. All the solutions I found is using strings to format the date but this isn't working for me since I am using Entity Framework, and Entity Framework is expecting a DateTime type variable to be passed to the model and NOT a string.

result.SurveyDate = Convert.ToDateTime(CurrentSurveryDateValue);

I can't do something like the above because this is sending a datatime2 DATATYPE to the my model result. Which throws this error...

The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value

Now I can't pass a string formatted to be of datetime format either because it throws a compile time error stating I can only pass DateTime types and not string...

How can i resolve this without changing the date datatype within my SQL table?

Renji
  • 43
  • 1
  • 7

0 Answers0