2009-03-12 4 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>