[英]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.