using System; using System.Collections.Generic; using System.Linq; namespace SqlSugar { public class QuestDBDbBind : DbBindProvider { public override string GetDbTypeName(string csharpTypeName) { if (csharpTypeName == UtilConstants.ByteArrayType.Name) return "binary"; var result = base.GetDbTypeName(csharpTypeName); return result; } 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) { if (dbTypeName.StartsWith("_")) { var dbTypeName2 = dbTypeName.TrimStart('_'); return MappingTypes.Where(it => it.Value.ToString().ToLower() == dbTypeName2 || it.Key.ToLower() == dbTypeName2).Select(it => it.Value + "[]").First(); } 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("byte",CSharpDataType.@byte), new KeyValuePair("short",CSharpDataType.@short), new KeyValuePair("smallint",CSharpDataType.@short), new KeyValuePair("int",CSharpDataType.@int), new KeyValuePair("integer",CSharpDataType.@int), new KeyValuePair("long",CSharpDataType.@long), new KeyValuePair("bigint",CSharpDataType.@long), new KeyValuePair("long256",CSharpDataType.@long), new KeyValuePair("float",CSharpDataType.@float), new KeyValuePair("real",CSharpDataType.@float), new KeyValuePair("double",CSharpDataType.@double), new KeyValuePair("double precision",CSharpDataType.@int), new KeyValuePair("double",CSharpDataType.@decimal), new KeyValuePair("decimal",CSharpDataType.@decimal), new KeyValuePair("path",CSharpDataType.@decimal), new KeyValuePair("point",CSharpDataType.@decimal), new KeyValuePair("polygon",CSharpDataType.@decimal), //new KeyValuePair("int",CSharpDataType.@bool), new KeyValuePair("boolean",CSharpDataType.@bool), new KeyValuePair("bool",CSharpDataType.@bool), new KeyValuePair("box",CSharpDataType.@bool), new KeyValuePair("bytea",CSharpDataType.@bool), new KeyValuePair("string",CSharpDataType.@string), new KeyValuePair("character varying",CSharpDataType.@string), new KeyValuePair("geometry",CSharpDataType.@string), new KeyValuePair("name",CSharpDataType.@string), new KeyValuePair("text",CSharpDataType.@string), new KeyValuePair("symbol",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("string",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("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("binary",CSharpDataType.byteArray), new KeyValuePair("bit varying",CSharpDataType.byteArray), new KeyValuePair("varbit",CSharpDataType.@byte), new KeyValuePair("time",CSharpDataType.TimeSpan), //new KeyValuePair("public.geometry",CSharpDataType.@object), new KeyValuePair("geohash",CSharpDataType.@string) }; public override List StringThrow { get { return new List() { "int32", "datetime", "decimal", "double", "byte" }; } } } }