【发布时间】:2017-12-30 06:07:37
【问题描述】:
比较日期时间中的年份时出现奇怪的异常。
示例代码:
_dbContext.Details.Where(x => x.Person.Birth.Year == date.Year);
Birth 和 date 都不能为空的 DateTime。
异常信息:
Message: System.ArgumentException : Property 'Int32 Year' is not defined for type 'System.Nullable`1[System.DateTime]'
我尝试在内存中设置数据库的情况下运行单元测试中的代码。
【问题讨论】:
-
Birth和date的类型有哪些? -
Person.Birth.Value.Year
-
它不能为空。在下面发布答案。
标签: c# entity-framework entity-framework-core