using System; using System.Collections.Generic; using System.Data; using System.Linq; using MySql.Data.MySqlClient; using Oracle.ManagedDataAccess.Client; namespace CSFramework.DB { /// /// C#数据类型转换DbType /// public static class DBDataTypes { /// /// .NET数据类型与DbType对应关系 /// public static IDictionary NetType2DbTypeMapping { get { IDictionary map = new Dictionary(); map[typeof(object)] = DbType.Object; map[typeof(byte)] = DbType.Byte; map[typeof(sbyte)] = DbType.SByte; map[typeof(short)] = DbType.Int16; map[typeof(ushort)] = DbType.UInt16; map[typeof(int)] = DbType.Int32; map[typeof(uint)] = DbType.UInt32; map[typeof(long)] = DbType.Int64; map[typeof(ulong)] = DbType.UInt64; map[typeof(float)] = DbType.Single; map[typeof(double)] = DbType.Double; map[typeof(decimal)] = DbType.Decimal; map[typeof(bool)] = DbType.Boolean; map[typeof(string)] = DbType.String; map[typeof(char)] = DbType.StringFixedLength; map[typeof(Guid)] = DbType.Guid; map[typeof(DateTime)] = DbType.DateTime; map[typeof(DateTimeOffset)] = DbType.DateTimeOffset; map[typeof(byte[])] = DbType.Binary; map[typeof(byte?)] = DbType.Byte; map[typeof(sbyte?)] = DbType.SByte; map[typeof(short?)] = DbType.Int16; map[typeof(ushort?)] = DbType.UInt16; map[typeof(int?)] = DbType.Int32; map[typeof(uint?)] = DbType.UInt32; map[typeof(long?)] = DbType.Int64; map[typeof(ulong?)] = DbType.UInt64; map[typeof(float?)] = DbType.Single; map[typeof(double?)] = DbType.Double; map[typeof(decimal?)] = DbType.Decimal; map[typeof(bool?)] = DbType.Boolean; map[typeof(char?)] = DbType.StringFixedLength; map[typeof(Guid?)] = DbType.Guid; map[typeof(DateTime?)] = DbType.DateTime; map[typeof(DateTimeOffset?)] = DbType.DateTimeOffset; return map; } } /// /// DbType与.NET数据类型对应关系 /// public static IDictionary DbType2NetTypeMapping { get { IDictionary map = new Dictionary(); map.Add(DbType.AnsiString, typeof(string)); map.Add(DbType.AnsiStringFixedLength, typeof(string)); map.Add(DbType.Binary, typeof(byte[])); map.Add(DbType.Boolean, typeof(bool)); map.Add(DbType.Byte, typeof(byte)); map.Add(DbType.Currency, typeof(decimal)); map.Add(DbType.Date, typeof(DateTime)); map.Add(DbType.DateTime, typeof(DateTime)); map.Add(DbType.DateTime2, typeof(DateTime)); map.Add(DbType.DateTimeOffset, typeof(DateTimeOffset)); map.Add(DbType.Decimal, typeof(decimal)); map.Add(DbType.Double, typeof(double)); map.Add(DbType.Guid, typeof(Guid)); map.Add(DbType.Int16, typeof(short)); map.Add(DbType.Int32, typeof(int)); map.Add(DbType.Int64, typeof(long)); map.Add(DbType.Object, typeof(object)); map.Add(DbType.SByte, typeof(sbyte)); map.Add(DbType.Single, typeof(float)); map.Add(DbType.String, typeof(string)); map.Add(DbType.StringFixedLength, typeof(string)); map.Add(DbType.Time, typeof(DateTime)); map.Add(DbType.UInt16, typeof(ushort)); map.Add(DbType.UInt32, typeof(uint)); map.Add(DbType.UInt64, typeof(ulong)); map.Add(DbType.VarNumeric, typeof(decimal)); map.Add(DbType.Xml, typeof(string)); return map; } } /// /// MsSql数据类型对应.NET类型-MsSql数据类型(SqlDbType)与.NET类型(Type)对应关系 /// public static IDictionary SqlDbType2NetTypeMapping { get { IDictionary map = new Dictionary(); map.Add(SqlDbType.BigInt, typeof(long)); map.Add(SqlDbType.Binary, typeof(byte[])); map.Add(SqlDbType.Bit, typeof(bool)); map.Add(SqlDbType.Char, typeof(char)); map.Add(SqlDbType.Date, typeof(DateTime)); map.Add(SqlDbType.DateTime, typeof(DateTime)); map.Add(SqlDbType.DateTime2, typeof(DateTime)); map.Add(SqlDbType.DateTimeOffset, typeof(DateTimeOffset)); map.Add(SqlDbType.Decimal, typeof(decimal)); map.Add(SqlDbType.Float, typeof(double)); map.Add(SqlDbType.Image, typeof(byte[])); map.Add(SqlDbType.Int, typeof(int)); map.Add(SqlDbType.Money, typeof(decimal)); map.Add(SqlDbType.NChar, typeof(string)); map.Add(SqlDbType.NText, typeof(string)); map.Add(SqlDbType.NVarChar, typeof(string)); map.Add(SqlDbType.Real, typeof(double)); //float类型,double map.Add(SqlDbType.SmallDateTime, typeof(DateTime)); map.Add(SqlDbType.SmallInt, typeof(short)); map.Add(SqlDbType.SmallMoney, typeof(decimal)); map.Add(SqlDbType.Structured, typeof(object)); map.Add(SqlDbType.Text, typeof(string)); map.Add(SqlDbType.Time, typeof(DateTime)); map.Add(SqlDbType.Timestamp, typeof(DateTime)); //byte[], 可以定义为datetime map.Add(SqlDbType.TinyInt, typeof(short)); map.Add(SqlDbType.Udt, typeof(object)); //UDT是用户自定义数据类型 map.Add(SqlDbType.UniqueIdentifier, typeof(Guid)); map.Add(SqlDbType.VarBinary, typeof(byte[])); map.Add(SqlDbType.VarChar, typeof(string)); map.Add(SqlDbType.Variant, typeof(object)); //sql_variant map.Add(SqlDbType.Xml, typeof(string)); return map; } } /// /// MySql数据类型对应.NET类型-MySql数据类型(MySqlDbType)与.NET类型(Type)对应关系 /// public static IDictionary MySqlDbType2NetTypeMapping { get { IDictionary map = new Dictionary(); map.Add(MySqlDbType.Binary, typeof(byte[])); map.Add(MySqlDbType.Bit, typeof(bool)); map.Add(MySqlDbType.Blob, typeof(byte[])); map.Add(MySqlDbType.Byte, typeof(byte)); map.Add(MySqlDbType.Date, typeof(DateTime)); map.Add(MySqlDbType.DateTime, typeof(DateTime)); map.Add(MySqlDbType.Decimal, typeof(decimal)); map.Add(MySqlDbType.Double, typeof(double)); map.Add(MySqlDbType.Enum, typeof(string)); //enum可以自定义类型,常用的是0,1,也可以定义为boy,girl,secret map.Add(MySqlDbType.Float, typeof(double)); map.Add(MySqlDbType.Geometry, typeof(object)); //几何图形 map.Add(MySqlDbType.Guid, typeof(Guid)); map.Add(MySqlDbType.Int16, typeof(short)); map.Add(MySqlDbType.Int24, typeof(int)); map.Add(MySqlDbType.Int32, typeof(int)); map.Add(MySqlDbType.Int64, typeof(long)); map.Add(MySqlDbType.JSON, typeof(string)); map.Add(MySqlDbType.LongBlob, typeof(byte[])); map.Add(MySqlDbType.LongText, typeof(string)); map.Add(MySqlDbType.MediumBlob, typeof(byte[])); map.Add(MySqlDbType.MediumText, typeof(string)); map.Add(MySqlDbType.Newdate, typeof(DateTime)); map.Add(MySqlDbType.NewDecimal, typeof(decimal)); map.Add(MySqlDbType.Set, typeof(string)); //集合 map.Add(MySqlDbType.String, typeof(string)); map.Add(MySqlDbType.Text, typeof(string)); map.Add(MySqlDbType.Time, typeof(DateTime)); map.Add(MySqlDbType.Timestamp, typeof(DateTime)); map.Add(MySqlDbType.TinyBlob, typeof(byte[])); map.Add(MySqlDbType.TinyText, typeof(string)); map.Add(MySqlDbType.UByte, typeof(byte)); map.Add(MySqlDbType.UInt16, typeof(ushort)); map.Add(MySqlDbType.UInt24, typeof(uint)); map.Add(MySqlDbType.UInt32, typeof(uint)); map.Add(MySqlDbType.UInt64, typeof(ulong)); map.Add(MySqlDbType.VarBinary, typeof(byte[])); map.Add(MySqlDbType.VarChar, typeof(string)); map.Add(MySqlDbType.VarString, typeof(string)); map.Add(MySqlDbType.Year, typeof(int)); return map; } } /// /// Oracle数据类型对应.NET类型 -Oracle数据类型(OracleDbType)与.NET类型(Type)对应关系 /// public static IDictionary OracleDbType2NetTypeMapping { get { IDictionary map = new Dictionary(); map.Add(OracleDbType.BFile, typeof(byte[])); map.Add(OracleDbType.BinaryDouble, typeof(double)); map.Add(OracleDbType.BinaryFloat, typeof(float)); map.Add(OracleDbType.Blob, typeof(byte[])); map.Add(OracleDbType.Boolean, typeof(bool)); map.Add(OracleDbType.Byte, typeof(byte)); map.Add(OracleDbType.Char, typeof(char)); map.Add(OracleDbType.Clob, typeof(string)); map.Add(OracleDbType.Date, typeof(DateTime)); map.Add(OracleDbType.Decimal, typeof(decimal)); map.Add(OracleDbType.Double, typeof(double)); map.Add(OracleDbType.Int16, typeof(short)); map.Add(OracleDbType.Int32, typeof(int)); map.Add(OracleDbType.Int64, typeof(long)); map.Add(OracleDbType.IntervalDS, typeof(double)); map.Add(OracleDbType.IntervalYM, typeof(int)); map.Add(OracleDbType.Long, typeof(string)); //Text map.Add(OracleDbType.LongRaw, typeof(byte[])); map.Add(OracleDbType.NChar, typeof(string)); map.Add(OracleDbType.NClob, typeof(string)); map.Add(OracleDbType.NVarchar2, typeof(string)); map.Add(OracleDbType.Raw, typeof(byte[])); map.Add(OracleDbType.RefCursor, typeof(object)); //游标类型,前端不使用 map.Add(OracleDbType.Single, typeof(float)); map.Add(OracleDbType.TimeStamp, typeof(DateTime)); map.Add(OracleDbType.TimeStampLTZ, typeof(DateTime)); map.Add(OracleDbType.TimeStampTZ, typeof(DateTime)); map.Add(OracleDbType.Varchar2, typeof(string)); map.Add(OracleDbType.XmlType, typeof(string)); return map; } } /// /// MsSql数据类型简称对应.NET类型 - MsSql数据类型(SqlDbType)名称对应.NET类型(Type) /// public static IDictionary SqlDbTypeName2NetTypeMapping { get { IDictionary map = new Dictionary(); map.Add("BigInt", typeof(long)); map.Add("Binary", typeof(byte[])); map.Add("Bit", typeof(bool)); map.Add("Char", typeof(char)); map.Add("Cursor", typeof(object)); //前端不用 map.Add("Date", typeof(DateTime)); map.Add("DateTime", typeof(DateTime)); map.Add("DateTime2", typeof(DateTime)); map.Add("DateTimeOffset", typeof(DateTimeOffset)); map.Add("Decimal", typeof(decimal)); map.Add("Float", typeof(double)); map.Add("Image", typeof(byte[])); map.Add("Int", typeof(int)); map.Add("Money", typeof(decimal)); map.Add("NChar", typeof(string)); map.Add("NText", typeof(string)); map.Add("NVarChar", typeof(string)); map.Add("Real", typeof(double)); //float类型,double map.Add("SmallDateTime", typeof(DateTime)); map.Add("SmallInt", typeof(short)); map.Add("SmallMoney", typeof(decimal)); map.Add("sql_variant", typeof(object)); //sql_variant map.Add("Structured", typeof(object)); //前端不用 map.Add("Text", typeof(string)); map.Add("Time", typeof(DateTime)); map.Add("Timestamp", typeof(DateTime)); //byte[], 可以定义为datetime map.Add("TinyInt", typeof(short)); map.Add("Udt", typeof(object)); //前端不用,UDT是用户自定义数据类型 map.Add("UniqueIdentifier", typeof(Guid)); map.Add("VarBinary", typeof(byte[])); map.Add("VarChar", typeof(string)); map.Add("Variant", typeof(object)); //sql_variant map.Add("Xml", typeof(string)); return map; } } /// /// MySql数据类型简称对应.NET类型 /// MySql数据类型(MySqlDbType)名称对应.NET类型(Type) /// public static IDictionary MySqlDbTypeName2NetTypeMapping { get { IDictionary map = new Dictionary(); map.Add("BigInt", typeof(long)); map.Add("Binary", typeof(byte[])); map.Add("Bit", typeof(bool)); map.Add("Blob", typeof(byte[])); map.Add("Char", typeof(char)); map.Add("Byte", typeof(byte)); map.Add("Date", typeof(DateTime)); map.Add("DateTime", typeof(DateTime)); map.Add("Decimal", typeof(decimal)); map.Add("Double", typeof(double)); map.Add("Enum", typeof(string)); //enum可以自定义类型,常用的是0,1,也可以定义为boy,girl,secret map.Add("Float", typeof(double)); map.Add("Geometry", typeof(object)); map.Add("Guid", typeof(Guid)); map.Add("Int", typeof(int)); map.Add("Integer", typeof(int)); map.Add("Int16", typeof(short)); map.Add("Int24", typeof(int)); map.Add("Int32", typeof(int)); map.Add("Int64", typeof(long)); map.Add("JSON", typeof(string)); map.Add("LongBlob", typeof(byte[])); map.Add("LongText", typeof(string)); map.Add("MediumBlob", typeof(byte[])); map.Add("MediumText", typeof(string)); map.Add("Newdate", typeof(DateTime)); map.Add("NewDecimal", typeof(decimal)); map.Add("Numeric", typeof(decimal)); map.Add("Real", typeof(double)); map.Add("Set", typeof(string)); map.Add("String", typeof(string)); map.Add("SmallInt", typeof(short)); map.Add("Text", typeof(string)); map.Add("Time", typeof(DateTime)); map.Add("Timestamp", typeof(DateTime)); map.Add("TinyBlob", typeof(byte[])); map.Add("TinyInt", typeof(short)); map.Add("TinyText", typeof(string)); map.Add("UByte", typeof(byte)); map.Add("UInt16", typeof(ushort)); map.Add("UInt24", typeof(uint)); map.Add("UInt32", typeof(uint)); map.Add("UInt64", typeof(ulong)); map.Add("VarBinary", typeof(byte[])); map.Add("VarChar", typeof(string)); map.Add("VarString", typeof(string)); map.Add("Year", typeof(int)); return map; } } /// /// Oracle数据类型名称(如:CLOB,BLOG)对应.NET类型 /// Oracle数据类型(OracleDbType)名称对应.NET类型(Type) /// public static IDictionary OracleDbTypeName2NetTypeMapping { get { IDictionary map = new Dictionary(); map.Add("BFile", typeof(byte[])); map.Add("Binary_Double", typeof(double)); map.Add("Binary_Float", typeof(float)); map.Add("Blob", typeof(byte[])); map.Add("Boolean", typeof(bool)); map.Add("Byte", typeof(byte)); map.Add("Char", typeof(char)); map.Add("Clob", typeof(string)); map.Add("Date", typeof(DateTime)); map.Add("Decimal", typeof(decimal)); map.Add("Double", typeof(double)); map.Add("Float", typeof(float)); map.Add("Int16", typeof(short)); map.Add("Int32", typeof(int)); map.Add("Int64", typeof(long)); map.Add("Integer", typeof(int)); map.Add("IntervalDS", typeof(double)); //OracleIntervalDS(double totalDays); map.Add("IntervalYM", typeof(int)); map.Add("Long", typeof(string)); //Text map.Add("LongRaw", typeof(byte[])); map.Add("NChar", typeof(string)); map.Add("NClob", typeof(string)); map.Add("Number", typeof(decimal)); map.Add("Numeric", typeof(decimal)); map.Add("NVarchar2", typeof(string)); map.Add("Raw", typeof(byte[])); map.Add("Real", typeof(decimal)); map.Add("RefCursor", typeof(object)); //游标类型 map.Add("RowID", typeof(string)); map.Add("Single", typeof(float)); map.Add("SmallInt", typeof(short)); map.Add("TimeStamp", typeof(DateTime)); map.Add("TimeStampLTZ", typeof(DateTime)); map.Add("TimeStampTZ", typeof(DateTime)); map.Add("UROWID", typeof(string)); map.Add("Varchar", typeof(string)); map.Add("Varchar2", typeof(string)); map.Add("XmlType", typeof(string)); return map; } } /// /// Oracle数据类型名称(如:CLOB,BLOG)对应DbType类型 /// Oracle数据类型(OracleDbType)名称对应DbType类型 /// public static IDictionary OracleDbTypeName2DbTypeMapping { get { IDictionary map = new Dictionary(); map.Add("BFile", DbType.Binary); map.Add("Binary_Double", DbType.Double); map.Add("Binary_Float", DbType.Single); map.Add("Blob", DbType.Binary); map.Add("Boolean", DbType.Boolean); map.Add("Byte", DbType.Byte); map.Add("Char", DbType.String); map.Add("Clob", DbType.String); map.Add("Date", DbType.Date); map.Add("Decimal", DbType.Decimal); map.Add("Double", DbType.Double); map.Add("Float", DbType.Single); map.Add("Int16", DbType.Int16); map.Add("Int32", DbType.Int32); map.Add("Int64", DbType.Int64); map.Add("Integer", DbType.Int32); map.Add("IntervalDS", DbType.Double); map.Add("IntervalYM", DbType.Int32); map.Add("Long", DbType.String); //Text map.Add("LongRaw", DbType.Binary); map.Add("NChar", DbType.String); map.Add("NClob", DbType.String); map.Add("Number", DbType.Decimal); map.Add("Numeric", DbType.Decimal); map.Add("NVarchar2", DbType.String); map.Add("Raw", DbType.Binary); map.Add("Real", DbType.Single); map.Add("RefCursor", DbType.Object); //游标类型:????????????????? map.Add("RowID", DbType.String); map.Add("Single", DbType.Single); map.Add("SmallInt", DbType.Int16); map.Add("TimeStamp", DbType.DateTime); map.Add("TimeStampLTZ", DbType.DateTime); map.Add("TimeStampTZ", DbType.DateTime); map.Add("UROWID", DbType.String); map.Add("Varchar", DbType.String); map.Add("Varchar2", DbType.String); map.Add("XmlType", DbType.Xml); return map; } } /// /// MsSQL数据类型名称(如:varchar,image)对应DbType类型 /// MsSQL数据类型(SqlDbType)名称对应DbType类型 /// public static IDictionary SqlDbTypeName2DbTypeMapping { get { IDictionary map = new Dictionary(); map.Add("BigInt", DbType.Int64); map.Add("Binary", DbType.Binary); map.Add("Bit", DbType.Boolean); map.Add("Char", DbType.String); map.Add("Cursor", DbType.Object); //前端不用 map.Add("Date", DbType.Date); map.Add("DateTime", DbType.DateTime); map.Add("DateTime2", DbType.DateTime2); map.Add("DateTimeOffset", DbType.DateTimeOffset); map.Add("Decimal", DbType.Decimal); map.Add("Float", DbType.Double); map.Add("Image", DbType.Binary); map.Add("Int", DbType.Int32); map.Add("Money", DbType.Decimal); map.Add("NChar", DbType.String); map.Add("NText", DbType.String); map.Add("NVarChar", DbType.String); map.Add("Real", DbType.Double); //float类型,double map.Add("SmallDateTime", DbType.Date); map.Add("SmallInt", DbType.Int16); map.Add("SmallMoney", DbType.Decimal); map.Add("sql_variant", DbType.Object); //sql_variant map.Add("Structured", DbType.Object); //前端不用 map.Add("Text", DbType.String); map.Add("Time", DbType.Time); map.Add("Timestamp", DbType.DateTime); //byte[], 可以定义为datetime map.Add("TinyInt", DbType.Int16); map.Add("Udt", DbType.Object); //前端不用,UDT是用户自定义数据类型 map.Add("UniqueIdentifier", DbType.Guid); map.Add("VarBinary", DbType.Binary); map.Add("VarChar", DbType.String); map.Add("Variant", DbType.Object); //sql_variant map.Add("Xml", DbType.Xml); return map; } } /// /// MySql数据类型(如:varchar)对应DbType类型 /// MySQL数据类型(MySqlDbType)数据类型名称对应DbType类型 /// public static IDictionary MySqlDbTypeName2DbTypeMapping { get { IDictionary map = new Dictionary(); map.Add("BigInt", DbType.Int64); map.Add("Binary", DbType.Binary); map.Add("Bit", DbType.Boolean); map.Add("Blob", DbType.Binary); map.Add("Char", DbType.AnsiStringFixedLength); map.Add("Byte", DbType.Byte); map.Add("Date", DbType.Date); map.Add("DateTime", DbType.DateTime); map.Add("Decimal", DbType.Decimal); map.Add("Double", DbType.Double); map.Add("Enum", DbType.String); //enum可以自定义类型,常用的是0,1,也可以定义为boy,girl,secret map.Add("Float", DbType.Double); map.Add("Geometry", DbType.Object); map.Add("Guid", DbType.Guid); map.Add("Int", DbType.Int32); map.Add("Integer", DbType.Int32); map.Add("Int16", DbType.Int16); map.Add("Int24", DbType.Int32); map.Add("Int32", DbType.Int32); map.Add("Int64", DbType.Int64); map.Add("JSON", DbType.String); map.Add("LongBlob", DbType.Binary); map.Add("LongText", DbType.String); map.Add("MediumBlob", DbType.Binary); map.Add("MediumText", DbType.String); map.Add("Newdate", DbType.DateTime); map.Add("NewDecimal", DbType.Decimal); map.Add("Numeric", DbType.Decimal); map.Add("Real", DbType.Double); map.Add("Set", DbType.String); map.Add("String", DbType.String); map.Add("SmallInt", DbType.Int16); map.Add("Text", DbType.String); map.Add("Time", DbType.Time); map.Add("Timestamp", DbType.DateTime); map.Add("TinyBlob", DbType.Binary); map.Add("TinyInt", DbType.Int16); map.Add("TinyText", DbType.String); map.Add("UByte", DbType.Byte); map.Add("UInt16", DbType.UInt16); map.Add("UInt24", DbType.UInt32); map.Add("UInt32", DbType.UInt32); map.Add("UInt64", DbType.UInt64); map.Add("VarBinary", DbType.Binary); map.Add("VarChar", DbType.String); map.Add("VarString", DbType.String); map.Add("Year", DbType.Int32); return map; } } /// /// .NET数据类型转DbType数据类型 /// /// .NET数据类型 /// public static DbType GetDbType(Type netType) { var map = NetType2DbTypeMapping; if (map.ContainsKey(netType)) return map[netType]; else return DbType.String; } /// /// .NET数据类型转DbType数据类型 /// /// .NET数据类型,如:string,double /// public static DbType GetDbType(string netTypeName) { if (string.IsNullOrEmpty(netTypeName)) return DbType.String; //名字空间 //System.String,System.Double if (netTypeName.ToLower().IndexOf("system.") < 0) netTypeName = "System." + netTypeName; var type = Type.GetType(netTypeName, true, true); return GetDbType(type); } /// /// DbType数据类型转.NET类型 /// /// DbType类型 /// public static Type GetNetType(DbType dbType) { var map = DbType2NetTypeMapping; if (map.ContainsKey(dbType)) return map[dbType]; else return typeof(string); } /// /// DbType数据类型转.NET类型简称,如:string/double /// /// DbType数据 /// true:返回简称如:String,false:返回全称如:System.String /// public static string GetNetType(DbType dbType, bool returnShortName = true) { var map = DbType2NetTypeMapping; if (map.ContainsKey(dbType)) return returnShortName ? map[dbType].Name : map[dbType].FullName; else return typeof(string).Name; } /// /// 获取.NET数据类型(Type) /// /// MsSQL数据类型 /// public static Type GetNetTypeByMsSql(string msSqlDbType) { var map = SqlDbTypeName2NetTypeMapping; var k = map.Keys.Where(e => e.ToLower() == msSqlDbType.ToLower()) .FirstOrDefault(); if (!string.IsNullOrWhiteSpace(k) && map.ContainsKey(k)) return map[k]; else return typeof(string); } /// /// 获取.NET数据类型(Type) /// /// MySQL数据类型 /// public static Type GetNetTypeByMySql(string mySqlDbType) { var map = MySqlDbTypeName2NetTypeMapping; var k = map.Keys .Where(e => e.ToString().ToLower() == mySqlDbType.ToLower()) .FirstOrDefault(); if (!string.IsNullOrWhiteSpace(k) && map.ContainsKey(k)) return map[k]; else return typeof(string); } /// /// 获取.NET数据类型(Type) /// /// Oracle数据类型 /// public static Type GetNetTypeByOracle(string oracleDbType) { var map = OracleDbTypeName2NetTypeMapping; var k = map.Keys .Where(e => e.ToString().ToLower() == oracleDbType.ToLower()) .FirstOrDefault(); if (!string.IsNullOrWhiteSpace(k) && map.ContainsKey(k)) return map[k]; else return typeof(string); } /// /// MsSQL数据库的数据类型转DbType /// /// MsSQL数据库的数据类型 /// public static DbType GetDbTypeByMsSqlType(string sqlDbTypeName) { var map = SqlDbTypeName2DbTypeMapping; var key = map.Keys .Where(e => e.ToLower() == sqlDbTypeName.ToLower()) .FirstOrDefault(); if (!string.IsNullOrWhiteSpace(key) && map.ContainsKey(key)) return map[key]; else return DbType.String; } /// /// MySQL数据库的数据类型转DbType /// /// MySQL数据库的数据类型 /// public static DbType GetDbTypeByMySqlType(string mySqlTypeName) { var map = MySqlDbTypeName2DbTypeMapping; var key = map.Keys .Where(e => e.ToLower() == mySqlTypeName.ToLower()) .FirstOrDefault(); if (!string.IsNullOrWhiteSpace(key) && map.ContainsKey(key)) return map[key]; else return DbType.String; } /// /// Oracle数据库的数据类型转DbType /// /// Oracle数据库的数据类型 /// public static DbType GetDbTypeByOracleType(string oracleDbTypeName) { var map = OracleDbTypeName2DbTypeMapping; var key = map.Keys .Where(e => e.ToLower() == oracleDbTypeName.ToLower()) .FirstOrDefault(); if (!string.IsNullOrWhiteSpace(key) && map.ContainsKey(key)) return map[key]; else return DbType.String; } } }