using System; using System.Collections.Generic; using System.Linq; namespace SqlSugar { public class PostgreSQLDbBind : DbBindProvider { public override string GetPropertyTypeName(string dbTypeName) { dbTypeName = dbTypeName.ToLower(); var propertyTypes = MappingTypes.Where(it => it.Value.ToString().ToLower() == dbTypeName || it.Key.ToLower() == dbTypeName); if (propertyTypes == null) { return "other"; } else if (dbTypeName == "xml" || dbTypeName == "string"|| dbTypeName == "jsonb"|| dbTypeName == "json") { return "string"; }else if (dbTypeName == "bpchar")//数据库char datatype 查询出来的时候是 bpchar { return "char"; } if (dbTypeName == "byte[]") { return "byte[]"; } else if (propertyTypes == null || propertyTypes.Count() == 0) { Check.ThrowNotSupportedException(string.Format(" \"{0}\" Type NotSupported, DbBindProvider.GetPropertyTypeName error.", dbTypeName)); return null; } else if (propertyTypes.First().Value == CSharpDataType.byteArray) { return "byte[]"; } else { return propertyTypes.First().Value.ToString(); } } public override List> MappingTypes { get { var extService = this.Context.CurrentConnectionConfig.ConfigureExternalServices; if (extService != null && extService.AppendDataReaderTypeMappings.HasValue()) { return extService.AppendDataReaderTypeMappings.Union(MappingTypesConst).ToList(); } else { return MappingTypesConst; } } } public static List> MappingTypesConst = new List>(){ new KeyValuePair("int2",CSharpDataType.@short), new KeyValuePair("smallint",CSharpDataType.@short), new KeyValuePair("int4",CSharpDataType.@int), new KeyValuePair("integer",CSharpDataType.@int), new KeyValuePair("int8",CSharpDataType.@long), new KeyValuePair("bigint",CSharpDataType.@long), new KeyValuePair("float4",CSharpDataType.@float), new KeyValuePair("real",CSharpDataType.@float), new KeyValuePair("float8",CSharpDataType.@double), new KeyValuePair("double precision",CSharpDataType.@int), new KeyValuePair("numeric",CSharpDataType.@decimal), new KeyValuePair("decimal",CSharpDataType.@decimal), new KeyValuePair("path",CSharpDataType.@decimal), new KeyValuePair("point",CSharpDataType.@decimal), new KeyValuePair("polygon",CSharpDataType.@decimal), new KeyValuePair("boolean",CSharpDataType.@bool), new KeyValuePair("bool",CSharpDataType.@bool), new KeyValuePair("box",CSharpDataType.@bool), new KeyValuePair("bytea",CSharpDataType.@bool), new KeyValuePair("varchar",CSharpDataType.@string), new KeyValuePair("character varying",CSharpDataType.@string), new KeyValuePair("text",CSharpDataType.@string), new KeyValuePair("char",CSharpDataType.@string), new KeyValuePair("character",CSharpDataType.@string), new KeyValuePair("cidr",CSharpDataType.@string), new KeyValuePair("circle",CSharpDataType.@string), new KeyValuePair("tsquery",CSharpDataType.@string), new KeyValuePair("tsvector",CSharpDataType.@string), new KeyValuePair("txid_snapshot",CSharpDataType.@string), new KeyValuePair("uuid",CSharpDataType.Guid), new KeyValuePair("xml",CSharpDataType.@string), new KeyValuePair("json",CSharpDataType.@string), new KeyValuePair("interval",CSharpDataType.@decimal), new KeyValuePair("lseg",CSharpDataType.@decimal), new KeyValuePair("macaddr",CSharpDataType.@decimal), new KeyValuePair("money",CSharpDataType.@decimal), new KeyValuePair("timestamp",CSharpDataType.DateTime), new KeyValuePair("timestamp with time zone",CSharpDataType.DateTime), new KeyValuePair("timestamptz",CSharpDataType.DateTime), new KeyValuePair("timestamp without time zone",CSharpDataType.DateTime), new KeyValuePair("date",CSharpDataType.DateTime), new KeyValuePair("time",CSharpDataType.DateTime), new KeyValuePair("time with time zone",CSharpDataType.DateTime), new KeyValuePair("timetz",CSharpDataType.DateTime), new KeyValuePair("time without time zone",CSharpDataType.DateTime), new KeyValuePair("bit",CSharpDataType.byteArray), new KeyValuePair("bit varying",CSharpDataType.byteArray), new KeyValuePair("varbit",CSharpDataType.@byte), }; public override List StringThrow { get { return new List() { "int32", "datetime", "decimal", "double", "byte" }; } } } }