References/has-a 通过 3 个表进行映射
我的模型对象 Reading
有一个 Location
但它在数据库中不是直接关系。在数据库中,此“has-a”关系或“引用”跨越 3 个表,如以下片段所示:
我的 Reading
映射到 ComponentReading 表,我希望我的 Location
映射到 Location 表。我的 ClassMap
类现在看起来像这样:
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(
代码甚至几乎是正确的,但它也试图传达我所追求的关系。
我希望有人能看到我在这里想做的事情。你能帮助我吗?
< a href="https://stackoverflow.com/q/5906163/56145">这个问题是相关的。
My model object Reading
has a Location
but it's not a direct relationship in the database. In the DB, this "has-a" relationship or "reference" spans 3 tables, as shown in this snip:
My Reading
maps to the ComponentReading table and i want my Location
to map to the Location table. My ClassMap<Reading>
class looks like this for now:
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");
}
}
And here is my simple Location
mapping:
public class LocationMap : ClassMap<Location>
{
public LocationMap()
{
Id(x => x.ID).Column("LocationId");
Map(x => x.Name);
}
}
The commented References(
method sort of shows what i want to achieve with the relationship between Reading
and Location
but obviously i can't express it to FNH as simply as the commented line suggests.
I don't think the Join(
code is even nearly correct either, but it also tries to communicate the relationship that i'm after.
I hope someone can see what i'm trying to do here. Can you help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你不能以这种方式嵌套连接。一个丑陋但实用的解决方案是(未经测试):
I think you cant nest joins that way. An ugly but pragmatic solution would be (untested):