开发者

Fluent nHibernate and interfaces

开发者 https://www.devze.com 2023-04-09 18:54 出处:网络
Does fluent nHibernate play well wh开发者_JAVA技巧en using interfaces instead of concrete classes as properties?

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

精彩评论

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

关注公众号