diff --git a/src/FluentCommand/Extensions/DataRecordExtensions.cs b/src/FluentCommand/Extensions/DataRecordExtensions.cs index b6b74396..55111e93 100644 --- a/src/FluentCommand/Extensions/DataRecordExtensions.cs +++ b/src/FluentCommand/Extensions/DataRecordExtensions.cs @@ -450,6 +450,9 @@ public static object GetValue(this IDataRecord dataRecord, string name) public static T GetValue(this IDataRecord dataRecord, string name) { int ordinal = dataRecord.GetOrdinal(name); + if (dataRecord.IsDBNull(ordinal)) + return default; + if (dataRecord is DbDataReader dataReader) return dataReader.GetFieldValue(ordinal); @@ -467,6 +470,9 @@ public static T GetValue(this IDataRecord dataRecord, string name) /// public static T GetValue(this IDataRecord dataRecord, int index) { + if (dataRecord.IsDBNull(index)) + return default; + if (dataRecord is DbDataReader dataReader) return dataReader.GetFieldValue(index);