c# - 自动映射类型为接口(interface)的属性

标签 c# nhibernate fluent-nhibernate

我有以下类(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/

相关文章:

c# - GridView 不显示带有 First() 查询扩展的结果

c# - ASP.NET 背景图片

sql-server - 使用 NHibernate 映射 XML 数据类型

c# - 为什么 NHibernate 不能在每个具体类映射的联合子类表中使用标识?

c# - 将 Linq 设置为 NHibernate ADO 命令超时

c# - 从日期列表创建日期范围

c# - 无法从我的 Silverlight 应用程序调用 Assembly.GetName()

c# - NHibernate : unexpected session trouble when persisting object

fluent-nhibernate - 为什么 Fluent NHibernate AutoMappings 在 Id 上添加下划线(例如 Entity_id)?

c# - 如何使用 NHibernate ICriteria 查询键值对列表?