我在将NHibernate映射到从一个基类派生的许多类时遇到问题。我想对我的解决方案实施审核功能,并希望在一个带有ParentId列的表中包含AuditLog记录。
课程:
public class AuditableObject
{
private Guid _ID;
private IEnumerable<AuditLog> _AUDIT;
public Guid Id { get => _ID; set => _ID = value; }
public IEnumerable<AuditLog> AuditLogs {get => _AUDIT; set => _AUDIT = value; }
}
public class DerivedOne : AuditableObject
{
...
}
public class DerivedTwo : AuditableObject
{
...
}
public class AuditLog
{
private Guid _ID;
private AuditableObject _PARENT;
public Guid Id { get => _ID; set => _ID = value; }
public AuditableObject Parent { get => _PARENT; set => _PARENT = value; }
}
映射:
public class DerivedOneMap : ClassMapping<DerivedOne>
{
Id(d => d.Id, g => g.Generator(Generators.GuidComb));
Bag(d => d.AuditLogs, map => map.Key(k => k.Column("Parent")), rel => rel.OneToMany());
}
public class DerivedTwoMap : ClassMapping<DerivedTwo>
{
Id(d => d.Id, g => g.Generator(Generators.GuidComb));
Bag(d => d.AuditLogs, map => map.Key(k => k.Column("Parent")), rel => rel.OneToMany());
}
public class AuditLog : ClassMapping<AuditLog>
{
Id(al => al.Id, g => g.Generator(Generators.GuidComb));
ManyToOne(al => al.Parent, map => map.Column("Id"));
}
当我尝试将任何AuditLog添加到AuditableObject的任何派生版本并将其保存到DB时,出现此错误:
An association from the table AuditLog refers to an unmapped class: AuditableObject
有什么想法我做错了吗?