'XXX'上的'XXX'属性无法设置为'null'值。您必须将此属性设置为类型为“System.DateTime”的非null值

时间:2013-12-27 11:54:08

标签: entity-framework

我在lambda表达式中编写一个select查询,其中一个列名(ResolveDate)为null,我收到以下错误:

The 'ResolveDate' property on 'Ticket' could not be set to a 'null' value. You must set this property to a non-null value of type 'System.DateTime'.

如何将此列设置为可空?我的意思是如果我的查询结果中的列为空,则不应该给出错误?

1 个答案:

答案 0 :(得分:7)

DateTime是一种引用类型。您需要在班级中使用Nullable DateTime。

DateTime? ResolveDate = null;

Nullable<DateTime> ResolveDate ;