1

Closed

SqlDateTime overflow when selecting null column

description

I have a table with nullable DateTime column. When I use IRepository.Get I get a SqlDateTime overflow exception whenever I select a record with null value in the DateTime field.

SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.

No files are attached

Closed Jan 19 at 11:49 PM by BertrandLeRoy

comments

Emil wrote Jan 19 at 3:31 PM

Sorry, my bad. I was misled from the exception because I got it on SELECT and didn't realized the case. Usually such exception might happen when you try to insert/update the value, but it is actually possible in the other way around too.

Once I changed the type to DateTime? it works fine.
Consider this WI closed and thanks for your invaluable help again.

BertrandLeRoy wrote Jan 18 at 7:43 PM

Sébastien means a nullable DataTime, the question mark is really important here.

sebastienros wrote Jan 18 at 4:37 PM

Did you check that the model also has a DateTime? property ? Otherwise it will fail as DateTime is a value type.