代码之家  ›  专栏  ›  技术社区  ›  Krzysztof Kozmic

如何使用SQL Server 2005在NHibernate中映射uint

  •  5
  • Krzysztof Kozmic  · 技术社区  · 16 年前

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

    4 回复  |  直到 16 年前
        1
  •  4
  •   Stefan Steinegger    16 年前

    最正式

    举个例子,比如 this one 并适应它。如果你有很多 uint 的,有一个用户类型是值得的。

    <property name="Prop" type="UIntUserType"/>
    
        2
  •  2
  •   KaraT    16 年前

    还没有尝试过,所以不确定这是否适用于您,但您可以尝试创建自己的方言并在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>
    
        3
  •  1
  •   Alex Reitbort    16 年前
    <property name="Prop" type="long"/>
    
        4
  •  0
  •   Stefan Steinegger    16 年前

    您可以尝试添加另一个私有“镜像”属性。

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

    如果映射无法解决。

    推荐文章