开发者

Fluent nHibernate and interfaces

Does fluent nHibernate play well wh开发者_JAVA技巧en 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"?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜