Browse Source

Code optimization

pull/12/MERGE
sunkaixuan 8 years ago
parent
commit
bb82797e5a
  1. 20
      SqlSugar/Abstract/DbBindProvider/DbBindProvider.cs
  2. 3
      SqlSugar/Enum/ProperyType.cs
  3. 1
      SqlSugar/Interface/IDbBind.cs
  4. 98
      SqlSugar/Realization/MySql/DbBind/MySqlDbBind.cs
  5. 115
      SqlSugar/Realization/SqlServer/DbBind/SqlServerDbBind.cs

20
SqlSugar/Abstract/DbBindProvider/DbBindProvider.cs

@ -14,7 +14,7 @@ namespace SqlSugar
#endregion
#region Public methods
public abstract string GetPropertyTypeName(string dbTypeName);
public abstract List<KeyValuePair<string, CSharpDataType>> MappingTypes { get; }
public virtual string GetConvertString(string dbTypeName)
{
string reval = string.Empty;
@ -117,6 +117,24 @@ namespace SqlSugar
}
return reval;
}
public virtual string GetPropertyTypeName(string dbTypeName)
{
dbTypeName = dbTypeName.ToLower();
var propertyTypes = MappingTypes.Where(it => it.Key == dbTypeName);
if (propertyTypes == null)
{
return "other";
}
else if (propertyTypes.First().Value == CSharpDataType.byteArray)
{
return "byte[]";
}
else
{
return propertyTypes.First().Value.ToString();
}
}
public virtual List<T> DataReaderToList<T>(Type type, IDataReader dataReader, string fields)
{
using (dataReader)

3
SqlSugar/Enum/ProperyType.cs

@ -20,6 +20,7 @@ namespace SqlSugar
@long,
@object,
@other,
@byteArray
@byteArray,
@float
}
}

1
SqlSugar/Interface/IDbBind.cs

@ -17,6 +17,7 @@ namespace SqlSugar
List<string> ShortThrow { get; }
string GetPropertyTypeName(string dbTypeName);
string GetConvertString(string dbTypeName);
List<KeyValuePair<string, CSharpDataType>> MappingTypes { get; }
List<T> DataReaderToList<T>(Type type, IDataReader reader, string fields);
}
}

98
SqlSugar/Realization/MySql/DbBind/MySqlDbBind.cs

@ -1,102 +1,16 @@
using System;
using System.Collections.Generic;
namespace SqlSugar
{
public class MySqlDbBind : DbBindProvider
{
public override string GetPropertyTypeName(string typeName)
public override List<KeyValuePair<string, CSharpDataType>> MappingTypes
{
string reval;
switch (typeName.ToLower())
{
case "int":
reval = "int";
break;
case "text":
reval = "string";
break;
case "bigint":
reval = "long";
break;
case "binary":
reval = "object";
break;
case "bit":
reval = "bool";
break;
case "char":
reval = "string";
break;
case "datetime":
case "date":
case "datetime2":
reval = "dateTime";
break;
case "single":
case "decimal":
reval = "decimal";
break;
case "float":
reval = "double";
break;
case "image":
reval = "byte[]";
break;
case "money":
reval = "decimal";
break;
case "nchar":
reval = "string";
break;
case "ntext":
reval = "string";
break;
case "numeric":
reval = "decimal";
break;
case "nvarchar":
reval = "string";
break;
case "real":
reval = "float";
break;
case "smalldatetime":
reval = "dateTime";
break;
case "smallint":
reval = "short";
break;
case "smallmoney":
reval = "decimal";
break;
case "timestamp":
reval = "dateTime";
break;
case "tinyint":
reval = "byte";
break;
case "uniqueidentifier":
reval = "guid";
break;
case "varbinary":
reval = "byte[]";
break;
case "varchar":
reval = "string";
break;
case "Variant":
reval = "object";
break;
default:
reval = "other";
break;
}
return reval;
}
public override string GetConvertString(string dbTypeName)
{
throw new NotImplementedException();
get
{
throw new NotImplementedException();
}
}
}
}

115
SqlSugar/Realization/SqlServer/DbBind/SqlServerDbBind.cs

@ -6,92 +6,41 @@ namespace SqlSugar
{
public class SqlServerDbBind : DbBindProvider
{
public override string GetPropertyTypeName(string dbTypeName)
public override List<KeyValuePair<string, CSharpDataType>> MappingTypes
{
string reval = string.Empty;
switch (dbTypeName.ToLower())
get
{
case "int":
reval = "int";
break;
case "text":
reval = "string";
break;
case "bigint":
reval = "long";
break;
case "bit":
reval = "bool";
break;
case "char":
reval = "string";
break;
case "datetime":
case "date":
case "datetime2":
reval = "DateTime";
break;
case "single":
case "decimal":
reval = "decimal";
break;
case "float":
reval = "double";
break;
case "binary":
case "image":
reval = "byte[]";
break;
case "money":
reval = "decimal";
break;
case "nchar":
reval = "string";
break;
case "ntext":
reval = "string";
break;
case "numeric":
reval = "decimal";
break;
case "nvarchar":
reval = "string";
break;
case "real":
reval = "float";
break;
case "smalldatetime":
reval = "DateTime";
break;
case "smallint":
reval = "short";
break;
case "smallmoney":
reval = "decimal";
break;
case "timestamp":
reval = "DateTime";
break;
case "tinyint":
reval = "byte";
break;
case "uniqueidentifier":
reval = "Guid";
break;
case "varbinary":
reval = "byte[]";
break;
case "varchar":
reval = "string";
break;
case "Variant":
reval = "object";
break;
default:
reval = "other";
break;
return new List<KeyValuePair<string, CSharpDataType>>()
{
new KeyValuePair<string, CSharpDataType>("int",CSharpDataType.@int),
new KeyValuePair<string, CSharpDataType>("sql_variant",CSharpDataType.@string),
new KeyValuePair<string, CSharpDataType>("text",CSharpDataType.@string),
new KeyValuePair<string, CSharpDataType>("char",CSharpDataType.@string),
new KeyValuePair<string, CSharpDataType>("ntext",CSharpDataType.@string),
new KeyValuePair<string, CSharpDataType>("nchar",CSharpDataType.@string),
new KeyValuePair<string, CSharpDataType>("varchar",CSharpDataType.@string),
new KeyValuePair<string, CSharpDataType>("nvarchar",CSharpDataType.@string),
new KeyValuePair<string, CSharpDataType>("bigint",CSharpDataType.@long),
new KeyValuePair<string, CSharpDataType>("bit",CSharpDataType.@bool),
new KeyValuePair<string, CSharpDataType>("datetime",CSharpDataType.DateTime),
new KeyValuePair<string, CSharpDataType>("smalldatetime",CSharpDataType.DateTime),
new KeyValuePair<string, CSharpDataType>("timestamp",CSharpDataType.DateTime),
new KeyValuePair<string, CSharpDataType>("datetime2",CSharpDataType.DateTime),
new KeyValuePair<string, CSharpDataType>("date",CSharpDataType.DateTime),
new KeyValuePair<string, CSharpDataType>("single",CSharpDataType.@decimal),
new KeyValuePair<string, CSharpDataType>("decimal",CSharpDataType.@decimal),
new KeyValuePair<string, CSharpDataType>("money",CSharpDataType.@decimal),
new KeyValuePair<string, CSharpDataType>("numeric",CSharpDataType.@decimal),
new KeyValuePair<string, CSharpDataType>("smallmoney",CSharpDataType.@decimal),
new KeyValuePair<string, CSharpDataType>("float",CSharpDataType.@double),
new KeyValuePair<string, CSharpDataType>("real",CSharpDataType.@float),
new KeyValuePair<string, CSharpDataType>("smallint",CSharpDataType.@short),
new KeyValuePair<string, CSharpDataType>("tinyint",CSharpDataType.@byte),
new KeyValuePair<string, CSharpDataType>("uniqueidentifier",CSharpDataType.Guid),
new KeyValuePair<string, CSharpDataType>("binary",CSharpDataType.byteArray),
new KeyValuePair<string, CSharpDataType>("image",CSharpDataType.byteArray),
new KeyValuePair<string, CSharpDataType>("varbinary",CSharpDataType.byteArray)};
}
return reval;
}
}
}

Loading…
Cancel
Save