using System; using System.Collections.Generic; using System.Linq; namespace SqlSugar { public class DmDbBind : DbBindProvider { public override string GetDbTypeName(string csharpTypeName) { if (csharpTypeName == UtilConstants.ByteArrayType.Name) return "blob"; if (csharpTypeName.ToLower() == "int32") csharpTypeName = "int"; if (csharpTypeName.ToLower() == "int16") csharpTypeName = "short"; if (csharpTypeName.ToLower() == "int64") csharpTypeName = "long"; if (csharpTypeName.ToLower().IsIn("boolean", "bool")) csharpTypeName = "bool"; if (csharpTypeName == "Guid") csharpTypeName = "string"; if (csharpTypeName == "DateTimeOffset") csharpTypeName = "DateTime"; var mappings = this.MappingTypes.Where(it => it.Value.ToString().Equals(csharpTypeName, StringComparison.CurrentCultureIgnoreCase)); return mappings.HasValue() ? mappings.First().Key : "varchar"; } public override string GetPropertyTypeName(string dbTypeName) { dbTypeName = dbTypeName.ToLower(); var propertyTypes = MappingTypes.Where(it => it.Value.ToString().ToLower() == dbTypeName || it.Key.ToLower() == dbTypeName); if (dbTypeName == "int32") { return "int"; } else if (dbTypeName == "int64") { return "long"; } else if (dbTypeName == "int16") { return "short"; } else if (propertyTypes == null) { return "other"; } else if (dbTypeName == "sbyte") { return "byte"; } else if (dbTypeName == "xml" || dbTypeName == "string") { return "string"; } 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("int",CSharpDataType.@int), new KeyValuePair("bigint",CSharpDataType.@long), new KeyValuePair("tinyint",CSharpDataType.@short), new KeyValuePair("smallint",CSharpDataType.@short), new KeyValuePair("integer",CSharpDataType.@int), new KeyValuePair("interval year to month",CSharpDataType.@int), new KeyValuePair("interval day to second",CSharpDataType.TimeSpan), new KeyValuePair("intervalds",CSharpDataType.TimeSpan), new KeyValuePair("number",CSharpDataType.@int), new KeyValuePair("number",CSharpDataType.@float), new KeyValuePair("number",CSharpDataType.@short), new KeyValuePair("number",CSharpDataType.@byte), new KeyValuePair("number",CSharpDataType.@double), new KeyValuePair("binaryfloat",CSharpDataType.@float), new KeyValuePair("binarydouble",CSharpDataType.@double), new KeyValuePair("number",CSharpDataType.@long), new KeyValuePair("number",CSharpDataType.@bool), new KeyValuePair("boolean",CSharpDataType.@bool), new KeyValuePair("bit",CSharpDataType.@bool), new KeyValuePair("decimal",CSharpDataType.@decimal), new KeyValuePair("number",CSharpDataType.@decimal), new KeyValuePair("numeric",CSharpDataType.@decimal), new KeyValuePair("number",CSharpDataType.Single), new KeyValuePair("decimal",CSharpDataType.Single), new KeyValuePair("dec",CSharpDataType.@decimal), new KeyValuePair("double precision",CSharpDataType.@double), new KeyValuePair("binary", CSharpDataType.@byteArray), new KeyValuePair("varchar",CSharpDataType.@string), new KeyValuePair("nvarchar",CSharpDataType.@string), new KeyValuePair("varchar",CSharpDataType.@Guid), new KeyValuePair("varchar2",CSharpDataType.@string), new KeyValuePair("nvarchar2",CSharpDataType.@string), new KeyValuePair("longvarchar",CSharpDataType.@string), new KeyValuePair("char",CSharpDataType.@string), new KeyValuePair("nchar",CSharpDataType.@string), new KeyValuePair("clob",CSharpDataType.@string), new KeyValuePair("text",CSharpDataType.@string), new KeyValuePair("long",CSharpDataType.@string), new KeyValuePair("nclob",CSharpDataType.@string), new KeyValuePair("rowid",CSharpDataType.@string), new KeyValuePair("timestamp",CSharpDataType.DateTime), new KeyValuePair("date",CSharpDataType.DateTime), new KeyValuePair("timestamp with local time zone",CSharpDataType.DateTime), new KeyValuePair("timestamp with time zone",CSharpDataType.DateTime), new KeyValuePair("timestamp with time zone",CSharpDataType.DateTime), new KeyValuePair("timestamp with local time zone",CSharpDataType.DateTimeOffset), new KeyValuePair("timestamp with time zone",CSharpDataType.DateTimeOffset), new KeyValuePair("timestamp with time zone",CSharpDataType.DateTimeOffset), new KeyValuePair("time",CSharpDataType.TimeSpan), new KeyValuePair("float",CSharpDataType.@decimal), new KeyValuePair("real",CSharpDataType.@float), new KeyValuePair("blob",CSharpDataType.byteArray), new KeyValuePair("image",CSharpDataType.byteArray), new KeyValuePair("long raw",CSharpDataType.byteArray), new KeyValuePair("raw",CSharpDataType.byteArray), new KeyValuePair("bfile",CSharpDataType.byteArray), new KeyValuePair("varbinary",CSharpDataType.byteArray) }; public override List StringThrow { get { return new List() { "int32", "datetime", "decimal", "double", "byte" }; } } } }