2009-03-12 18 views
5

私は自分のエンティティにuint型のプロパティを持っています。ような何か:SQL Server 2005でNHibernateのuintをマップする方法

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

私はSQL Server 2005のデータベースにそれを保持しようとすると、私は方言がどうなるかDbType.UInt32

をサポートしていません

例外を取得これを回避する最も簡単な方法です。私は、例えば、それをDBに長く保管することができます。 私はそれをNHibernateに伝えるしかありません。

答えて

4

クリーン、最も公式ソリューションは、おそらくユーザーのタイプを記述することです。

たとえば、this oneのように入力してください。 uintが多い場合は、ユーザータイプを持つ価値があります。

<property name="Prop" type="UIntUserType"/> 
+0

ええ、それは私が最終的にやったことです。助けてくれてありがとう、皆さん。 –

1
<property name="Prop" type="long"/> 
+0

その後、あなたは=「長い」SchemaExportのは、あなたはNHibernateはのどのバージョンを使用しますBIGINT –

+0

より良い私にとってはこれ* *でした仕事の問題を...記述する必要がありますすることができますか? –

+0

としてフィールドをエクスポートするタイプで少し –

0

別のプライベート "ミラー"プロパティを追加できます。もちろん

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"/> 

それがマッピングでは解決できなかった場合は、こののみを行う必要があります。

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> 
関連する問題