Weird exception (with the simplest solution) after playing with Entity Framework

I have been playing with Entity framework Code-First approach (this is definitely the way I am going to use for my next project, i love it). Anyway, doesn’t matter if it is Code-First or Database-First approach, from time to time I keep on getting an exception:

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

It always takes few minutes to remember - what was that. Ah… It happens when You do not initialize DateTime properties when adding objects to database. Of course, that don’t have to be Your problem dear reader but as it happened to me for the third time I assume It should be pretty common one. Seriously, if for the third time You dig for solution of a known to You problem - that means You are getting old buddy.

comments powered by Disqus