using System; using System.Collections.Generic; using System.Linq; namespace SqlSugar { public class MySqlDbBind : DbBindProvider { public override string GetDbTypeName(string csharpTypeName) { if (csharpTypeName == UtilConstants.ByteArrayType.Name) { return "blob"; } if (csharpTypeName == "Int32") csharpTypeName = "int"; if (csharpTypeName == "Int16") csharpTypeName = "short"; if (csharpTypeName == "Int64") csharpTypeName = "long"; if (csharpTypeName == "Boolean") csharpTypeName = "bool"; var mappings = this.MappingTypes.Where(it => it.Value.ToString().Equals(csharpTypeName, StringComparison.CurrentCultureIgnoreCase)); return mappings.HasValue() ? mappings.First().Key : "varchar"; } 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("mediumint",CSharpDataType.@int), new KeyValuePair("integer",CSharpDataType.@int), new KeyValuePair("varchar",CSharpDataType.@string), new KeyValuePair("text",CSharpDataType.@string), new KeyValuePair("char",CSharpDataType.@string), new KeyValuePair("enum",CSharpDataType.@string), new KeyValuePair("mediumtext",CSharpDataType.@string), new KeyValuePair("tinytext",CSharpDataType.@string), new KeyValuePair("longtext",CSharpDataType.@string), new KeyValuePair("tinyint",CSharpDataType.@byte), new KeyValuePair("smallint",CSharpDataType.@short), new KeyValuePair("bigint",CSharpDataType.@long), new KeyValuePair("bit",CSharpDataType.@bool), new KeyValuePair("real",CSharpDataType.@double), new KeyValuePair("double",CSharpDataType.@double), new KeyValuePair("float",CSharpDataType.@float), new KeyValuePair("float",CSharpDataType.Single), new KeyValuePair("decimal",CSharpDataType.@decimal), new KeyValuePair("numeric",CSharpDataType.@decimal), new KeyValuePair("year",CSharpDataType.@int), new KeyValuePair("datetime",CSharpDataType.DateTime), new KeyValuePair("timestamp",CSharpDataType.DateTime), new KeyValuePair("date",CSharpDataType.DateTime), new KeyValuePair("time",CSharpDataType.DateTime), new KeyValuePair("blob",CSharpDataType.byteArray), new KeyValuePair("tinyblob",CSharpDataType.byteArray), new KeyValuePair("varbinary",CSharpDataType.byteArray), new KeyValuePair("binary",CSharpDataType.byteArray), new KeyValuePair("multipoint",CSharpDataType.byteArray), new KeyValuePair("geometry",CSharpDataType.byteArray), new KeyValuePair("multilinestring",CSharpDataType.byteArray), new KeyValuePair("polygon",CSharpDataType.byteArray), new KeyValuePair("mediumblob",CSharpDataType.byteArray), new KeyValuePair("varchar",CSharpDataType.Guid), }; public override List StringThrow { get { return new List { "int32", "datetime", "decimal", "double", "byte" }; } } } }