当前位置: 动力学知识库 > 问答 > 编程问答 >

entity framework - 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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: