Newbie
Newbie

Reputation: 187

Troubleshooting 'Column is null' issues using Postgres and EF core

Been trying to troubleshoot an issue where one of our queries results in the following error message:

System.InvalidCastException: Column is null at Npgsql.NpgsqlDataReader.GetFieldValue[T](Int32 ordinal) at Npgsql.NpgsqlDataReader.GetString(Int32 ordinal)

Is there any way to determine what column it's complaining about? Usually I can troubleshoot this but unfortunately the query hits a ton of tables and was wondering if there was some magic code that would indicate which column it's complaining about when EF core is attempting to shove it into a model.

Upvotes: 3

Views: 3983

Answers (1)

user2767633
user2767633

Reputation: 67

If Data type is DateTime, then don't keep it null. Or if you want to return with null then allow null.

public DateTime? ColumnName { get; set; }

Upvotes: 4

Related Questions