C# 自动映射类型为接口的属性

C# 自动映射类型为接口的属性,c#,nhibernate,fluent-nhibernate,C#,Nhibernate,Fluent Nhibernate,我有以下课程 class MCustomer : DomanEntity { public MCustomer() { } public virtual iCustomerEntity CustomerDetials { get; set; } public virtual SolicitationPreferences SolicitationPreferences { get; set; } } public interface iC

我有以下课程

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; }
}
class MCCustomer:DomainEntity
{
公共mccustomer()
{       
}
公共虚拟ICCustomerEntity CustomerDatials{get;set;}
公共虚拟请求首选项请求首选项{get;set;}
}
公共接口ICCustomerEntity
{
联系人{get;set;}
}
公共类个人:域名实体、iCustomerEntity
{
公共人格
{
intrest=新列表();
Children=新列表();
}
公共虚拟联系人联系人{get;set;}
公共虚拟日期时间出生日期{get;set;}
公共虚拟IList intrest{get;set;}
公共虚拟人配偶{get;set;}
公共虚拟IList子项{get;set;}
}
当我使用fluent NHibernate自动映射时,我收到以下错误:

NHibernate.MappingException:表MCCustomer中的关联引用了未映射的类:Calyx.Core.Domain.CRM.ICCustomerEntity


如何在域模型中设置具有接口类型的属性?

我不认为您可以这样做。
当您尝试加载您的MCCustomer(
session.load(id)
)时,NHibernate只知道您想要获取具有ICCustomerEntity的MCCustomer。它不知道使用哪个实现(PersonEntity或CoderEntity?)。它如何知道使用哪个映射来检索ICCustomerEntity的数据呢?

在我看来就像一个“任意”映射。你应该调查一下。据我所知,FNH还不支持这一点。

这是一种标准的无纤维图案。我也在试着做同样的事情