문제

나는 내 엔티티에 유형 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"/>

다른 개인 "미러"-프로 테티를 추가하려고 시도 할 수 있습니다.

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

물론 당신은 이것을해야합니다 매핑으로 해결할 수없는 경우.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top