C#.NET数据类型(Type)与DbType的对应关系
![](http://www.csframework.com/images/article-type5.gif)
![C#.NET数据类型(Type)与DbType的对应关系 C#.NET数据类型(Type)与DbType的对应关系](http://www.csframework.com/images/seo/SEO-%E5%A4%9A%E6%95%B0%E6%8D%AE%E5%BA%93.jpg)
C# Code:
/// <summary>
/// .NET数据类型与DbType对应关系
/// </summary>
public static IDictionary<Type, DbType> NetType2DbTypeMapping
{
get
{
IDictionary<Type, DbType> map = new Dictionary<Type, DbType>();
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;
}
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
/// <summary>
/// .NET数据类型与DbType对应关系
/// </summary>
public static IDictionary<Type, DbType> NetType2DbTypeMapping
{
get
{
IDictionary<Type, DbType> map = new Dictionary<Type, DbType>();
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;
}
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
![C/S框架网|原创精神.创造价值.打造精品](http://www.csframework.com/images/our03.gif)
扫一扫加微信
![C/S框架网作者微信](http://www.csframework.com/images/wechatcode.jpg)
![C/S框架网|原创作品.质量保障.竭诚为您服务](http://www.csframework.com/images/CS框架网提供高效优质服务.jpg)
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网