Simple.Data.Npgsql by Chris Hogan,Yaroslav Tatarenko

<PackageReference Include="Simple.Data.Npgsql" Version="0.19.1" />

 TypeMap

public class TypeMap
using NpgsqlTypes; using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Net; namespace Simple.Data.Npgsql { public class TypeMap { private static readonly Dictionary<string, TypeEntry> PgTypeToTypeEntry = new Dictionary<string, TypeEntry> { { "smallint", new TypeEntry("smallint", DbType.Int16, 18, typeof(short)) }, { "integer", new TypeEntry("integer", DbType.Int32, 9, typeof(int)) }, { "bigint", new TypeEntry("bigint", DbType.Int64, 1, typeof(long)) }, { "decimal", new TypeEntry("decimal", DbType.Decimal, 13, typeof(decimal)) }, { "numeric", new TypeEntry("numeric", DbType.Decimal, 13, typeof(decimal)) }, { "real", new TypeEntry("numeric", DbType.Single, 17, typeof(float)) }, { "double precision", new TypeEntry("double precision", DbType.Double, 8, typeof(double)) }, { "money", new TypeEntry("money", DbType.Currency, 12, typeof(decimal)) }, { "character varying", new TypeEntry("character varying", DbType.String, 22, typeof(string)) }, { "character", new TypeEntry("character varying", DbType.String, 19, typeof(string)) }, { "text", new TypeEntry("text", DbType.String, 19, typeof(string)) }, { "bytea", new TypeEntry("bytea", DbType.Binary, 4, typeof(byte[])) }, { "timestamp without time zone", new TypeEntry("timestamp without time zone", DbType.DateTime, 21, typeof(DateTime)) }, { "timestamp with time zone", new TypeEntry("timestamp with time zone", DbType.DateTime, 26, typeof(DateTime)) }, { "date", new TypeEntry("date", DbType.Date, 7, typeof(DateTime)) }, { "time without time zone", new TypeEntry("time without time zone", DbType.Time, 20, typeof(DateTime)) }, { "time with time zone", new TypeEntry("time with time zone", DbType.Time, 31, typeof(DateTime)) }, { "interval", new TypeEntry("interval", DbType.Object, 30, typeof(TimeSpan)) }, { "boolean", new TypeEntry("boolean", DbType.Boolean, 2, typeof(bool)) }, { "point", new TypeEntry("point", DbType.Object, 15, typeof(NpgsqlPoint)) }, { "lseg", new TypeEntry("lseg", DbType.Object, 11, typeof(NpgsqlLSeg)) }, { "box", new TypeEntry("box", DbType.Object, 3, typeof(NpgsqlBox)) }, { "path", new TypeEntry("path", DbType.Object, 14, typeof(NpgsqlPath)) }, { "polygon", new TypeEntry("polygon", DbType.Object, 16, typeof(NpgsqlPolygon)) }, { "circle", new TypeEntry("circle", DbType.Object, 5, typeof(NpgsqlCircle)) }, { "cidr", new TypeEntry("cidr", DbType.String, 19, typeof(string)) }, { "inet", new TypeEntry("inet", DbType.Object, 24, typeof(IPAddress)) }, { "macaddr", new TypeEntry("macaddr", DbType.String, 19, typeof(string)) }, { "bit", new TypeEntry("bit", DbType.Object, 25, typeof(BitArray)) }, { "bit varying", new TypeEntry("bit varying", DbType.String, 19, typeof(string)) }, { "tsvector", new TypeEntry("tsvector", DbType.String, 19, typeof(string)) }, { "tsquery", new TypeEntry("tsquery", DbType.String, 19, typeof(string)) }, { "uuid", new TypeEntry("uuid", DbType.Guid, 27, typeof(Guid)) }, { "oid", new TypeEntry("oid", DbType.Int64, 1, typeof(long)) }, { "ARRAY", new TypeEntry("ARRAY", DbType.Object, -2147483648, typeof(object)) }, { "USER-DEFINED", new TypeEntry("USER-DEFINED", DbType.Object, 4, typeof(object)) }, { "refcursor", new TypeEntry("refcursor", DbType.Object, 4, typeof(object)) } }; public static TypeEntry GetTypeEntry(string dataType, string elementType = null) { if (!PgTypeToTypeEntry.ContainsKey(dataType)) throw new ArgumentException($"""{dataType}"); return PgTypeToTypeEntry[dataType]; } } }