0

Does fluent nHibernate play well when using interfaces instead of concrete classes as properties?

E.g. A sports stadium has a reference to a city that it is in, so our interfaces/concrete classes looks as follows

Interface:

ICity  
  int Id;  
  string Name;  

IStadium
 int Id;  
 string Name;  
 ICity City;

Concrete class:

class City: ICity;  
   ...

class Stadium: IStadium;
  public virtual int Id {get; private set; }  
  public virtual string Name { get; set; }
  public virtual ICity City { get; set; } //<- NOTE: Reference to interface instead of the class

Mapper:

public class StadiumMap : ClassMap<Stadium>
{
    public StadiumMap() 
    {
       ...
       References(x => x.City).Column("Id");
       ...
    }
}

So will the above work fine in fluent nhibernate or will I have to replace my "ICity" with "City"?

Eminem
  • 7,206
  • 15
  • 53
  • 95

1 Answers1

0

A little off topic but I doubt your domain classes are benefiting from implementing interfaces. James Gregory said it best.

Community
  • 1
  • 1
LordHits
  • 5,054
  • 3
  • 38
  • 51
  • Thanks for pointing out that link. That thread is indeed useful. However its not a case of if my domain classes are benefitting from implementing interfaces but its a case of "will it work"?. I will investigate the issue further drawing from a comment made further in the thread http://stackoverflow.com/questions/845536/programming-to-interfaces-while-mapping-with-fluent-nhibernate/1130856#1130856 – Eminem Oct 03 '11 at 21:59