From 5ff91baac2d8047bad0a27cfc955afe94dbb8aa9 Mon Sep 17 00:00:00 2001 From: Paul Welter Date: Thu, 8 Aug 2024 12:30:47 -0500 Subject: [PATCH] Update DataRecordExtensions.cs --- src/FluentCommand/Extensions/DataRecordExtensions.cs | 6 ++++++ 1 file changed, 6 insertions(+) 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);