0

我有一个班级员工,例如:

  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; }
    }
 }

我想在一张员工表中进行映射。我可以配置和运行一切,但我的公共类 EmployeeMap : ClassMapping 不正确。任何人都可以帮助我并使用代码映射在此处编写它吗?

4

2 回答 2

0

像这样,我是 nh 的新手,甚至不知道每个命令的含义

       { 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());
    }
于 2013-05-13T04:41:42.380 回答
0

在 Mapping-by-code 上翻译这个 Fluent(working) 就足够了

 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();
于 2013-05-13T05:09:26.223 回答