关于 没有从 DbType UInt16 到已知 SqlDbType 的映射。的Bug追踪.

public override DbType DbType
{
get
{
return this.GetMetaTypeOnly().DbType;
}
set
{
MetaType type = this._metaType;
if (((type == null) || (type.DbType != value)) || ((value == DbType.Date) || (value == DbType.Time)))
{
this.PropertyTypeChanging();
this._metaType = MetaType.GetMetaTypeFromDbType(value);
}
}
}

上面是 SqlParameter 的DbType 源码.调用以下方法.

 

internal static MetaType GetMetaTypeFromDbType(DbType target)
{
switch (target)
{
case DbType.AnsiString:
return MetaVarChar;

case DbType.Binary:
return MetaVarBinary;

case DbType.Byte:
return MetaTinyInt;

case DbType.Boolean:
return MetaBit;

case DbType.Currency:
return MetaMoney;

case DbType.Date:
case DbType.DateTime:
return MetaDateTime;

case DbType.Decimal:
return MetaDecimal;

case DbType.Double:
return MetaFloat;

case DbType.Guid:
return MetaUniqueId;

case DbType.Int16:
return MetaSmallInt;

case DbType.Int32:
return MetaInt;

case DbType.Int64:
return MetaBigInt;

case DbType.Object:
return MetaVariant;

case DbType.Single:
return MetaReal;

case DbType.String:
return MetaNVarChar;

case DbType.Time:
return MetaDateTime;

case DbType.AnsiStringFixedLength:
return MetaChar;

case DbType.StringFixedLength:
return MetaNChar;

case DbType.Xml:
return MetaXml;

case DbType.DateTime2:
return MetaDateTime2;

case DbType.DateTimeOffset:
return MetaDateTimeOffset;
}
throw ADP.DbTypeNotSupported(target, typeof(SqlDbType));
}


可以看到. 有些DbType 它没有处理, 直接抛出了错误.

没有处理的DbType包括:

SByte=14,
UInt16=18,
UInt32=19,
UInt64=20,
VarNumeric=21,

 

个人觉着, 即使不需要, 做一下兼容性处理, 也不麻烦啊. 留下这么大一坑!

 

posted @ 2011-12-26 16:02  NewSea  阅读(2021)  评论(3编辑  收藏  举报