Skip to content

Commit

Permalink
string and byte[] : add UseGetFieldValue to prevent problems with npg…
Browse files Browse the repository at this point in the history
…sql using global deserializer
  • Loading branch information
mgravell committed Mar 6, 2024
1 parent 360367c commit 86c64a2
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Dapper/SqlMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ public TypeMapEntry(DbType dbType, TypeMapEntryFlags flags)
public bool Equals(TypeMapEntry other) => other.DbType == DbType && other.Flags == Flags;
public static readonly TypeMapEntry
DoNotSet = new((DbType)(-2), TypeMapEntryFlags.None),
DecimalFieldValue = new(DbType.Decimal, TypeMapEntryFlags.SetType | TypeMapEntryFlags.UseGetFieldValue);
DecimalFieldValue = new(DbType.Decimal, TypeMapEntryFlags.SetType | TypeMapEntryFlags.UseGetFieldValue),
StringFieldValue = new(DbType.String, TypeMapEntryFlags.SetType | TypeMapEntryFlags.UseGetFieldValue),
BinaryFieldValue = new(DbType.Binary, TypeMapEntryFlags.SetType | TypeMapEntryFlags.UseGetFieldValue);

public static implicit operator TypeMapEntry(DbType dbType)
=> new(dbType, TypeMapEntryFlags.SetType);
Expand All @@ -214,13 +216,13 @@ static SqlMapper()
[typeof(double)] = DbType.Double,
[typeof(decimal)] = DbType.Decimal,
[typeof(bool)] = DbType.Boolean,
[typeof(string)] = DbType.String,
[typeof(string)] = TypeMapEntry.StringFieldValue,
[typeof(char)] = DbType.StringFixedLength,
[typeof(Guid)] = DbType.Guid,
[typeof(DateTime)] = TypeMapEntry.DoNotSet,
[typeof(DateTimeOffset)] = DbType.DateTimeOffset,
[typeof(TimeSpan)] = TypeMapEntry.DoNotSet,
[typeof(byte[])] = DbType.Binary,
[typeof(byte[])] = TypeMapEntry.BinaryFieldValue,
[typeof(byte?)] = DbType.Byte,
[typeof(sbyte?)] = DbType.SByte,
[typeof(short?)] = DbType.Int16,
Expand Down

0 comments on commit 86c64a2

Please sign in to comment.