一、问题描述:
Unhandled Exception: System.Data.SqlTypes.SqlNullValueException: Data is Null. This method or property cannot be called on Null values.
at System.Data.SqlClient.SqlBuffer.get_DateTime()
at System.Data.SqlClient.SqlDataReader.GetDateTime(Int32 i)
二、原因分析:
EF Core模型读到日期为Null的字段。
三、解决方案:
1、设置日期为可空类型
public class Student
{
public int Id { get; set; }
// public DateTime Entry_Date { get; set; }
public DateTime? Entry_Date { get; set; }
}
2、修改数据。