2013-05-07 126 views
0

我有一個類員工水木清華這樣的:通過代碼問題NHibernate的映射

public class Employee{ 

    private List<Employee> subord = new List<Employee>(); 
    private int id; 
    private string surname; 
    public virtual Employee Boss { get; set; } 
    public virtual List<Employee> Subbord { get; set; } 
    public virtual int Id 
    { 
     get { return this.id; } 
     set { this.id = value; } 
    } 

    public virtual string Surname 
    { 
     get { return this.surname; } 
     set { this.surname = value; } 
    } 
} 

我想一個Employee表中的映射。我可以配置和運行一切,但是我的公共類EmployeeMap:ClassMapping不正確。任何人都可以幫助我,並使用代碼映射在這裏寫它?

+0

你使用的是FluentNHibernate,你試過了什麼? – hcb 2013-05-07 13:51:32

+4

你可以發佈你迄今爲止創建的映射代碼嗎? – gwin003 2013-05-07 13:53:04

+0

請看看,我打印不工作的嘗試 – 2013-05-13 04:42:26

回答

0

水木清華這樣的,我在新罕布什爾州新的,甚至不ectually知道每個命令意味着

 { this.Table("Employee"); 
     this.Id(
      x => x.Id, 
      m => 
       { 
        m.Generator(Generators.Sequence); 
       m.UnsavedValue(0); 
      }); 
     this.Property(x => x.Surname, m => m.Column("surname")); 
     this.ManyToOne(x => x.Boss, m => { m.Column("bossid");}); 
     this.Set(
      x => x.Subbord, 
      collectionMapping => 
       { 
        collectionMapping.Table("Employee"); 
        collectionMapping.Cascade(Cascade.All); 
        collectionMapping.Inverse(true); 

        collectionMapping.Key(
         k => 
          { 
           k.Column("bossid"); 

           k.ForeignKey("fk_Employee_BossEmployee"); 
          }); 
       }, 
     map => map.OneToMany()); 
    } 
0

它actuaaly足夠多的把這種良好的映射,通過代碼

Id(x => x.Id).GeneratedBy.Native(); 

    Map(x => x.Name) 
     .Length(200) 
     .Not.Nullable(); 

    References(x => x.ParentCategory) 
     .Column("ParentCategoryId") 
     .Access.CamelCaseField(); 

    HasMany(x => x.ChildCategories) 
     .Cascade.AllDeleteOrphan() 
     .AsSet() 
     .KeyColumn("ParentCategoryId") 
     .Access.CamelCaseField(); 
(工作)