如何地图uint在它能够与SQL服务器2005年
-
11-07-2019 - |
题
我有一个酒店的类型uint在我的实体。是这样的:
public class Enity
{
public uint Count {get;set;}
}
当我试图坚持得到SQL服务器2005年数据库中,我得到一个异常
话不支持DbType.UInt32
什么会是最简单的方法解决办法这一点。我可以例如存储,只要在数据库。我只是不知道怎么告诉它能够.
解决方案
最干净, 最官 解决方案可能会写用户的类型。
举个例子,就像 这一个 并且适应它。如果你有很多 uint
's,这是值得拥有一个用户的类型。
<property name="Prop" type="UIntUserType"/>
其他提示
没有试过所以不知道这是否会为你工作,但你可以尝试创建自己的方言和登记在web.config /的app.config
方言类:
public class MyDialect:MsSql2005Dialect
{
public MyDialect()
{
RegisterColumnType(System.Data.DbType.UInt32, "bigint");
}
}
的Web.config:
configuration>
<configSections>
<section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
</configSections>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider, NHibernate</property>
<property name="connection.connection_string">
Server=127.0.0.1; Initial Catalog=thedatabase; Integrated Security=SSPI
</property>
<property name="dialect">MyDialect</property>
<property name="current_session_context_class">managed_web</property>
</session-factory>
</hibernate-configuration>
<!-- other app specific config follows -->
</configuration>
<property name="Prop" type="long"/>
您可以尝试添加另一个私人的“镜子” - 属性。
public class Enity
{
public uint Count {get;set;}
private long CountAsLong
{
get { return Convert.ToInt64(Count); }
set { Count = Convert.ToUInt(value); }
}
}
<property name="CountAsLong" type="long"/>
当然,你应该这样做的仅如果它不能被映射来解决。
不隶属于 StackOverflow