我有以下类(class)
class MCustomer : DomanEntity
{
public MCustomer()
{
}
public virtual iCustomerEntity CustomerDetials { get; set; }
public virtual SolicitationPreferences SolicitationPreferences { get; set; }
}
public interface iCustomerEntity
{
Contact Contact { get; set; }
}
public class PersonEntity: DomanEntity, iCustomerEntity
{
public PersonEntity()
{
Intrests = new List<Intrest>();
Children = new List<PersonEntity>();
}
public virtual Contact Contact { get; set; }
public virtual DateTime BirthDate { get; set; }
public virtual IList<Intrest> Intrests { get; set; }
public virtual PersonEntity Spouse { get; set; }
public virtual IList<PersonEntity> Children { get; set; }
}
当我使用流畅的 NHibernate AutoMapping 时,我收到此错误:
NHibernate.MappingException: An association from the table MCustomer refers to an unmapped class: Calyx.Core.Domain.CRM.iCustomerEntity
如何在我的域模型中设置具有接口(interface)类型的属性?
最佳答案
我认为你做不到。
当您尝试加载您的 MCustomer ( session.Load<MCustomer>(id)
) 时,NHibernate 只会知道您想要获取具有 iCustomerEntity 的 MCustomer。它不知道要使用哪个实现(PersonEntity 或 CoderEntity?)。它如何知道使用哪个映射来检索 iCustomerEntity 的数据?
关于c# - 自动映射类型为接口(interface)的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/941454/