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



我正在 lambda 表达式中编写一个选择查询,其中列名之一 ( 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'.

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

DateTime 是一种引用类型。您需要在类中使用可为空的日期时间。

DateTime? ResolveDate = null;

Nullable<DateTime> ResolveDate ;

最新更新