SqlNullValueException: Data is Null. This method or property cannot be called on Null values.

1. Problem description:

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 model read a Null date field.

solution:
1. Set the date as nullable type

public class Student
{
  public int Id { get; set; }
  // public DateTime Entry_Date { get; set; }
  public DateTime? Entry_Date { get; set; }
}

2. Modify data.


Read More: