我已经看过如何使用旧的子类语法执行此操作的示例,但没有使用更新的子类语法。
基本上,我在表格中有多个鉴别器,需要弄清楚如何用FNH做这个。
谢谢, 萨姆
答案 0 :(得分:0)
我们有一个基类用户和许多派生类,作为学习者,评估者,经理,管理员等。
这是UserMap
public class UserMap : ClassMap<User>
{
public UserMap()
{
this.Id(x => x.Id);
this.Map(x => x.Active);
this.Component(
x => x.Address,
m =>
{
m.Map(x => x.Address1).Length(512);
m.Map(x => x.Address2);
m.Map(x => x.Address3);
m.Map(x => x.Address4);
m.Map(x => x.City);
m.Map(x => x.County);
m.Map(x => x.PostCode);
m.References(x => x.Country);
});
this.References(x => x.CreatedBy);
this.Map(x => x.CreatedDate).Not.Nullable();
this.Map(x => x.DeletedDate);
this.References(x => x.DeletedBy);
this.Map(x => x.Email);
this.Map(x => x.Fax);
this.Map(x => x.FirstName);
this.References(x => x.Gender);
this.Map(x => x.LastName);
this.Map(x => x.LoginName).UniqueKey("ui_loginName").Not.Nullable();
this.Map(x => x.MiddleName);
this.Map(x => x.Password);
this.DiscriminateSubClassesOnColumn("className").Length(64);
}
}
和经理的一个例子
public class ManagerMap : SubclassMap<Manager>
{
#region Constructors and Destructors
/// <summary>
/// Initializes a new instance of the <see cref="ManagerMap"/> class.
/// </summary>
public ManagerMap()
{
this.HasManyToMany(x => x.Organisation)
.ParentKeyColumn("userId")
.ChildKeyColumn("organisationId")
.Table("UserOrganisations");
this.HasMany(x => x.Learners)
.KeyColumn("managerId")
.AsBag();
}
#endregion
}
希望能帮助你。