C#.NET数据类型(Type)与DbType的对应关系
作者:C/S框架网|www.cscode.ne  发布日期:2021-06-08 10:47:57
  C#.NET数据类型(Type)与DbType的对应关系

C#.NET数据类型(Type)与DbType的对应关系


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




C/S框架网|原创精神.创造价值.打造精品

扫一扫加微信
C/S框架网作者微信 C/S框架网|原创作品.质量保障.竭诚为您服务

上一篇 下一篇