我正在尝试在我的应用程序中支持 UInt32。通过查看此位置给出的示例,我编写了我的代码。 NHibernate - 如何将 UInt32 存储在数据库中。在我的 hbm 文件中,我定义了属性标签:
<property name="Uint16Var" column="Uint16Var"
type="datatypeSupported.UInt32Type, datatypeSupported" />
我还定义了一个 UInt32Type 类,如下所示:
using System;
using NHibernate;
using NHibernate.SqlTypes;
using NHibernate.UserTypes;
namespace datatypeSupported
{
public class UInt32Type : IUserType
{
public object NullSafeGet(System.Data.IDataReader rs, string[] names, object owner)
{
int? i = (int?)NHibernateUtil.Int32.NullSafeGet(rs, names[0]);
return (UInt32?)i;
}
public void NullSafeSet(System.Data.IDbCommand cmd, object value, int index)
{
UInt32? u = (UInt32?)value;
int? i = (Int32?)u;
NHibernateUtil.Int32.NullSafeSet(cmd, i, index);
}
public Type ReturnedType
{
get
{
return typeof(Nullable<UInt32>);
}
}
public SqlType[] SqlTypes
{
get
{
return new SqlType[] { SqlTypeFactory.Int32 };
}
} public object Assemble(object cached, object owner)
{
return cached;
}
public object DeepCopy(object value)
{
return value;
}
public object Disassemble(object value)
{
return value;
}
public int GetHashCode(object x)
{
return x.GetHashCode();
}
public bool IsMutable
{
get { return false; }
}
public object Replace(object original, object target, object owner)
{
return original;
}
public new bool Equals(object x, object y)
{
return x != null && x.Equals(y);
}
}
}
但是当我尝试保存我的实体时,它仍然给出错误“方言不支持 DbType.UInt32”。我需要做什么类型的更改?