NHibernate - How to store UInt32 in database

前端 未结 2 1022
既然无缘
既然无缘 2020-12-12 07:30

What is the best way to map UInt32 type to sql-server int type with NHibernate.

The value is a picture width/height so negative value are not make sense here.

<
2条回答
  •  余生分开走
    2020-12-12 07:58

    I'm a year late, but since I had the same question and found a different answer I thought I'd add it. It seems simpler. Maybe it has a flaw I haven't discovered yet.

    I'm using NHibernate 3.0, Visual Studio 2005, and .NET 2.0.x.

    I found I could use .NET's UInt32 class and not include the type attribute in the hbm.xml.

    // .NET 2.0 Property syntax
    public class MyClass
    {
       // NHibernate needs public virtual properties. 
       private UInt32 _Id;
       public virtual UInt32 Id { get { return (_Id); } set { _Id = value; } }
    }
    
    
    // hbml.xml
    
       
    
    
    
    // SQL to create the table
    CREATE TABLE `PumpConnection` (
    `Id` **INT**(10) **UNSIGNED** NOT NULL AUTO_INCREMENT,
    )
    

提交回复
热议问题