最新消息:把Logo换了一下,虽然丑了点,但至少完全是自己的设计

C#中OracleDbType和DbType的对应关系

CSharp 宇托 1024浏览 暂无评论

之前在看OracleDbType和DbType的值,发现两者并不是一一对应的。在网上找了一下,两者的关系。呵呵,不列表了,直接上代码。

C#
public static DbType OracleDbTypeToDbType(OracleDbType oraDbType) {
    switch (oraDbType) {
        case OracleDbType.VarChar:
        case OracleDbType.Char:
        case OracleDbType.RowId:
        case OracleDbType.NChar:
        case OracleDbType.NVarChar:
        case OracleDbType.NClob:
        case OracleDbType.Xml:
            return DbType.String;
        case OracleDbType.Integer:
            return DbType.Int32;
        case OracleDbType.Float:
            return DbType.Single;
        case OracleDbType.Double:
            return DbType.Double;
        case OracleDbType.Number:
            return DbType.Decimal;
        case OracleDbType.Date:
        case OracleDbType.TimeStamp:
        case OracleDbType.TimeStampTZ:
        case OracleDbType.TimeStampLTZ:
            return DbType.DateTime;
        case OracleDbType.IntervalDS:
            return DbType.Time;
        case OracleDbType.IntervalYM:
            return DbType.Int32;
        case OracleDbType.Long:
        case OracleDbType.Clob:
            return DbType.String;
        case OracleDbType.Raw:
        case OracleDbType.LongRaw:
        case OracleDbType.Blob:
        case OracleDbType.BFile:
            return DbType.Binary;
        case OracleDbType.Cursor:
        case OracleDbType.Array:
        case OracleDbType.Object:
        case OracleDbType.Ref:
        case OracleDbType.Table:
            return DbType.Object;
        case OracleDbType.Boolean:
            return DbType.Boolean;
        default:
            throw new NotSupportedException();
    }
}

public static OracleDbType DbTypeToOracleDbType(DbType dbType) {
    switch (dbType) {
        case DbType.AnsiString:
        case DbType.String:
            return OracleDbType.VarChar;
        case DbType.AnsiStringFixedLength:
        case DbType.StringFixedLength:
            return OracleDbType.Char;
        case DbType.Byte:
        case DbType.Int16:
        case DbType.SByte:
        case DbType.UInt16:
        case DbType.Int32:
            return OracleDbType.Integer;
        case DbType.Single:
            return OracleDbType.Float;
        case DbType.Double:
            return OracleDbType.Double;
        case DbType.Date:
            return OracleDbType.Date;
        case DbType.DateTime:
            return OracleDbType.TimeStamp;
        case DbType.Time:
            return OracleDbType.IntervalDS;
        case DbType.Binary:
            return OracleDbType.Blob;
        case DbType.Boolean:
            return OracleDbType.Boolean;
        case DbType.Int64:
        case DbType.UInt64:
        case DbType.VarNumeric:
        case DbType.Decimal:
        case DbType.Currency:
            return OracleDbType.Number;
        case DbType.Object:
            return OracleDbType.Object;
        case DbType.Guid:
            return OracleDbType.Raw;
        default:
            throw new NotSupportedException();
    }
}

参考地址:
DbProviderFactory: Oracle-Type -> DbType Mapping?

转载请注明:宇托的狗窝 » C#中OracleDbType和DbType的对应关系

发表我的评论
取消评论

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址