[英]nhibernate mapping by code problems
我有一个班级员工,像:
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不正确。 有人可以帮助我,并使用代码映射在这里写吗?
像这样,我是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());
}
它足以在代码映射上翻译此流利的(有效的)代码
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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.