【发布时间】:2011-05-09 02:29:24
【问题描述】:
我的模型对象Reading 有一个Location,但它不是数据库中的直接关系。在 DB 中,这种“具有”关系或“引用”跨越 3 个表,如下图所示:
我的 Reading 映射到 ComponentReading 表,我希望我的 Location 映射到 Location 表。我的ClassMap<Reading> 班级现在看起来像这样:
public class ReadingMap : ClassMap<Reading>
{
public ReadingMap()
{
Table("ComponentReading");
Id(x => x.ID).Column("ComponentReadingId");
//References(x => x.Location).Formula(
Join("VehicleReading", vr =>
{
Join("TrainReading", tr =>
{
tr.References(x => x.Location, "LocationId");
});
});
Map(x => x.TemperatureValue).Column("Temperature");
}
}
这是我的简单Location 映射:
public class LocationMap : ClassMap<Location>
{
public LocationMap()
{
Id(x => x.ID).Column("LocationId");
Map(x => x.Name);
}
}
注释的References( 方法显示了我想要通过Reading 和Location 之间的关系实现的目标,但显然我不能像注释行所暗示的那样简单地将其表达给FNH。
我也不认为Join( 代码几乎是正确的,但它也试图传达我所追求的关系。
我希望有人能看到我在这里尝试做什么。你能帮帮我吗?
【问题讨论】:
标签: nhibernate orm join fluent-nhibernate domain-driven-design