可空字段不能接受空值?

Nullable field cannot accept null?

使用 EF 6。我有一个包含可为 null 的日期时间字段的实体 (Person)。

public DateTime? StartDate { get; set; }

这让我觉得我应该能够毫无问题地将 null 分配给这个 属性,就像这样...

Person.StartDate = null;

但是,当我到达 context.SaveChanges() 时,我收到一条错误消息说 ...

The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value.\r\nThe statement has been terminated."

可为空的字段不应该接受....null

让你的数据库列也可以为空。