سؤال

لدي عقار من نوع uint على الكيان.شيء من هذا القبيل:

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

عندما أحاول أن تستمر في قاعدة بيانات SQL Server 2005 ، أحصل على استثناء

لهجة لا يدعم DbType.UInt32

ماذا سيكون أسهل طريقة الحل هذه.لا يمكن على سبيل المثال متجر أنها طويلة في ديسيبل.أنا فقط لا أعرف كيف أقول هذا NHibernate.

هل كانت مفيدة؟

المحلول

وأنظف، <م> الأكثر مسؤول الحل ربما يكون لكتابة نوع المستخدم.

ونأخذ مثالا على ذلك، مثل <وأ href = "http://www.lostechies.com/blogs/rhouston/archive/2008/03/23/mapping-strings-to-booleans-using-nhibernate-s-iusertype .aspx اتصال "يختلط =" نوفولو noreferrer "> هذا واحد و تكييفه. إذا كان لديك في كثير 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