エンティティに uint 型のプロパティがあります。何かのようなもの:
public class Enity
{
public uint Count {get;set;}
}
それを SQL Server 2005 データベースに永続化しようとすると、例外が発生します
方言は DbType.UInt32 をサポートしていません
これを回避する最も簡単な方法は何でしょうか。たとえば、DBにできるだけ長く保存できます。それをNHibernateに伝える方法がわかりません。
エンティティに uint 型のプロパティがあります。何かのようなもの:
public class Enity
{
public uint Count {get;set;}
}
それを SQL Server 2005 データベースに永続化しようとすると、例外が発生します
方言は DbType.UInt32 をサポートしていません
これを回避する最も簡単な方法は何でしょうか。たとえば、DBにできるだけ長く保存できます。それをNHibernateに伝える方法がわかりません。
最もクリーンで最も公式な解決策は、おそらくユーザータイプを書くことでしょう。
このような例を取り上げて、それを適応させます。'が多い場合uint
は、ユーザータイプを設定する価値があります。
<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"/>
You could try to add another private "mirror"-property.
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"/>
Of course you should do this only if it could not be solved by the mapping.