5

エンティティに uint 型のプロパティがあります。何かのようなもの:

public class Enity
{
   public uint Count {get;set;}
}

それを SQL Server 2005 データベースに永続化しようとすると、例外が発生します

方言は DbType.UInt32 をサポートしていません

これを回避する最も簡単な方法は何でしょうか。たとえば、DBにできるだけ長く保存できます。それをNHibernateに伝える方法がわかりません。

4

4 に答える 4

4

最もクリーンで最も公式な解決策は、おそらくユーザータイプを書くことでしょう。

このような例を取り上げて、それを適応させます。'が多い場合uintは、ユーザータイプを設定する価値があります。

<property name="Prop" type="UIntUserType"/>
于 2009-05-27T09:10:00.410 に答える
2

これを試したことがないので、これがうまくいくかどうかはわかりませんが、独自の方言を作成して 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>
于 2009-05-21T05:19:52.150 に答える
1
<property name="Prop" type="long"/>
于 2009-03-12T16:43:44.380 に答える
0

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.

于 2009-05-20T09:22:37.513 に答える