2011-10-02 94 views
0

當使用接口而不是具體類作爲屬性時,流暢的nHibernate會發揮出色嗎?流利的nHibernate和接口

E.g.體育館有一個城市,它是一個參考,所以我們的接口/混凝土類看起來如下

接口:

ICity 
    int Id; 
    string Name; 

IStadium 
int Id; 
string Name; 
ICity City; 

混凝土類:

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"); 
     ... 
    } 
} 

那麼上面的工作會流利的nhibernate罰款或將我必須取代我的「ICity」與「城市」?

回答

0

有點偏離主題,但我懷疑你的域類受益於實現接口。 James Gregory said it best

+0

感謝您指出該鏈接。該線程確實有用。但是,如果我的域類受益於實現接口,但它不是一個「它會工作」的例子嗎?我將調查進一步從線程進一步繪製的問題http://stackoverflow.com/questions/845536/programming-to-interfaces-while-mapping-with-fluent-nhibernate/1130856#1130856 – Eminem