简体   繁体   English

在流畅的nHibernate中将平面视图映射到类层次结构

[英]Mapping a flat view to class hierarchy in fluent nHibernate

I'm developing an app that has a model using race results / times etc.. 我正在开发一个使用比赛结果/时间等模型的应用程序。
I've got a model that looks something like: 我有一个看起来像这样的模型:

public class Competitor
{
    public virtual int ID { get; set; }
    public virtual string Name { get; set; }
    public virtual DateTime DateOfBirth { get; set; }
}

public class Event
{
    public virtual int ID { get; set; }
    public virtual string Name { get; set; }
    public virtual string Description { get; set; }
}

public class Result
{
    public virtual int ID { get; set; }
    public virtual decimal ResultTime { get; set; }
    public virtual Competitor Competitor { get; set; }
    public virtual Event Event { get; set; }
}

In my database, I only have access to Views which represent a "flat" view of the data. 在我的数据库中,我只能访问代表数据“平面”视图的视图。 This would look something like: 这看起来像是这样的:

vResult vResult

ResultID ResultID
ResultTime ResultTime
CompetitorID CompetitorID
CompetitorName CompetitorName
CompetitorDateOfBirth CompetitorDateOfBirth
EventID 事件ID
EventName 事件名称
EventDescription EventDescription

So, I'm trying to avoid having a class that matches the above "flat" schema entirely (if possible) 所以,我试图避免让一个完全匹配上述“扁平”模式的类(如果可能的话)

Is it possibly to map this with Fluent nHibernate? 是否可以使用Fluent nHibernate进行映射?

EDIT- 编辑-
It's worth mentioning, data access will be read only 值得一提的是,数据访问将是只读的

As comments above indicated, it was indeed Component that solved this. 正如上面的评论所表明的,确实是Component解决了这个问题。

Along the lines of the following in my ResultMap class: 在我的ResultMap类中沿着以下几行:

Component(x => x.Event, m =>
            {
                m.Map(x => x.ID).Column("EventID");
                m.Map(x => x.Name).Column("EventName");
                m.Map(x => x.Description).Column("EventDescription");
            });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM