@@ -192,7 +192,9 @@ public TypeMapEntry(DbType dbType, TypeMapEntryFlags flags)
192192 public bool Equals ( TypeMapEntry other ) => other . DbType == DbType && other . Flags == Flags ;
193193 public static readonly TypeMapEntry
194194 DoNotSet = new ( ( DbType ) ( - 2 ) , TypeMapEntryFlags . None ) ,
195- DecimalFieldValue = new ( DbType . Decimal , TypeMapEntryFlags . SetType | TypeMapEntryFlags . UseGetFieldValue ) ;
195+ DecimalFieldValue = new ( DbType . Decimal , TypeMapEntryFlags . SetType | TypeMapEntryFlags . UseGetFieldValue ) ,
196+ StringFieldValue = new ( DbType . String , TypeMapEntryFlags . SetType | TypeMapEntryFlags . UseGetFieldValue ) ,
197+ BinaryFieldValue = new ( DbType . Binary , TypeMapEntryFlags . SetType | TypeMapEntryFlags . UseGetFieldValue ) ;
196198
197199 public static implicit operator TypeMapEntry ( DbType dbType )
198200 => new ( dbType , TypeMapEntryFlags . SetType ) ;
@@ -214,13 +216,13 @@ static SqlMapper()
214216 [ typeof ( double ) ] = DbType . Double ,
215217 [ typeof ( decimal ) ] = DbType . Decimal ,
216218 [ typeof ( bool ) ] = DbType . Boolean ,
217- [ typeof ( string ) ] = DbType . String ,
219+ [ typeof ( string ) ] = TypeMapEntry . StringFieldValue ,
218220 [ typeof ( char ) ] = DbType . StringFixedLength ,
219221 [ typeof ( Guid ) ] = DbType . Guid ,
220222 [ typeof ( DateTime ) ] = TypeMapEntry . DoNotSet ,
221223 [ typeof ( DateTimeOffset ) ] = DbType . DateTimeOffset ,
222224 [ typeof ( TimeSpan ) ] = TypeMapEntry . DoNotSet ,
223- [ typeof ( byte [ ] ) ] = DbType . Binary ,
225+ [ typeof ( byte [ ] ) ] = TypeMapEntry . BinaryFieldValue ,
224226 [ typeof ( byte ? ) ] = DbType . Byte ,
225227 [ typeof ( sbyte ? ) ] = DbType . SByte ,
226228 [ typeof ( short ? ) ] = DbType . Int16 ,
@@ -3905,7 +3907,11 @@ public static void ThrowDataException(Exception ex, int index, IDataReader reade
39053907 }
39063908 try
39073909 {
3908- if ( value is null || value is DBNull )
3910+ if ( value is null && ex is InvalidCastException )
3911+ {
3912+ formattedValue = "n/a - " + ex . Message ; // provide some context
3913+ }
3914+ else if ( value is null || value is DBNull )
39093915 {
39103916 formattedValue = "<null>" ;
39113917 }
0 commit comments