帮助我的类的属性映射

时间:2009-11-29 21:48:04

标签: nhibernate nhibernate-mapping

我的班级看起来像:

public class User
{
      public virtual int ID {get;set;}
      public virtual string Username {get;set;}

}

表:

User
-UserID INT NOT NULL,
-Username NVARCHAR(50) NOT NULL

UserID is the PK, IDENTITY.

我如何为我的班级使用nhibernate属性映射?

1 个答案:

答案 0 :(得分:1)

[Class(0, Name = "User", Table = "Users")]
public class User
{
      [Id(0, Name = ID", Type = "Int32", Column = "ID")]
      [Generator(1, Class = "native")]
      public virtual int ID {get;set;}
      [Property(0, Name = "Username", Column = "Username", Type = "string", NotNull = true , Length = 50)]
      public virtual string Username {get;set;}    
}