我有一个班级员工,如:
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 :(得分:0)
{ 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());
}
答案 1 :(得分:0)
实际上,在按代码映射
上翻译这个Fluent(工作)就足够了 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();