Finding the DateTime field that is not initialized
We are saving more than one entity type in one unit of work. There are many DateTime fields in each entity-type. Sometimes, an SqlDateTime overflow开发者_开发技巧 exception occurs because a DateTime field is not initialized.
To find the field/property that causes the problem is an annoying task. Does anybody know a debugging technique to find out which field is causing the problem? To check every field is cumbersome.
Thanks a lot for hints.
If you're using the DateTime? nullable type then you can use the property hasValue to check if it is null. If you're using DateTime then I believe it defaults to the min value which is DateTime.MinValue and can be easily checked. The MinValue is something insane like the year Jan 1st 0001, so it makes sense that SQL wouldn't like that
If you're taking something out of the db, then a standard null check works fine.
精彩评论