views:

223

answers:

3

I have the following 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;
     }
    }

When I use fluent NHibernate AutoMapping I receive the following error: NHibernate.MappingException: An association from the table MCustomer refers to an unmapped class: Calyx.Core.Domain.CRM.iCustomerEntity

How do I set up a property in my domain model that has a Interface type?

+1  A: 

I don't think, that you can do that.
When you would try to load your MCustomer (session.Load<MCustomer>(id)), NHibernate would only know, that you want to get MCustomer, that has an iCustomerEntity. It would not know which implementation (PersonEntity or CoderEntity?) to use. How would it know which mapping to use to retrieve the data for iCustomerEntity?

Mindaugas Mozūras
A: 

Looks like a "any" mapping to me. You should look into that. And as far as I can see FNH does not support that yet.

jl
A: 

https://www.hibernate.org/hib%5Fdocs/nhibernate/html/inheritance.html

Its a standard Nhibernate pattern. I'm trying to do the same thing

Thejuan