From 5cc7438bc94f62197108a3f3e5405a747bbc8884 Mon Sep 17 00:00:00 2001 From: AlexGreatDev Date: Tue, 13 May 2025 19:24:58 +0330 Subject: [PATCH] fix: handle nullable decimal by returning 0m if null (closes #1573) --- Dapper/SqlMapper.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Dapper/SqlMapper.cs b/Dapper/SqlMapper.cs index d23e949a5..d8ac0fa01 100644 --- a/Dapper/SqlMapper.cs +++ b/Dapper/SqlMapper.cs @@ -1973,6 +1973,11 @@ private static Func GetDeserializer(Type type, DbDataReade } return GetTypeDeserializer(type, reader, startBound, length, returnNullIfFirstMissing); } + // Patch for nullable decimal issue + if (type == typeof(decimal?)) + { + return r => r.IsDBNull(startBound) ? (object)0m : r.GetDecimal(startBound); + } return GetSimpleValueDeserializer(type, underlyingType ?? type, startBound, useGetFieldValue); }