流畅的 nHibernate 和接口
当使用接口而不是具体类作为属性时,Fluent nHibernate 运行良好吗?
例如,体育场有对其所在城市的引用,因此我们的接口/具体类如下所示
接口:
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
映射器:
public class StadiumMap : ClassMap<Stadium>
{
public StadiumMap()
{
...
References(x => x.City).Column("Id");
...
}
}
在流畅的nhibernate中可以正常工作吗?还是我必须用“City”替换我的“ICity”?
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"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有点偏离主题,但我怀疑您的域类是否从实现接口中受益。 詹姆斯·格雷戈里说得最好。
A little off topic but I doubt your domain classes are benefiting from implementing interfaces. James Gregory said it best.