映射一个平面视图类层次结构中的功能NHibernate [英] Mapping a flat view to class hierarchy in fluent nHibernate

查看:137
本文介绍了映射一个平面视图类层次结构中的功能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; }
}

在我的数据库,我只能访问其重新present数据的平面视图查看。这看起来是这样的:

In my database, I only have access to Views which represent a "flat" view of the data. This would look something like:

vResult

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

ResultID
ResultTime
CompetitorID
CompetitorName
CompetitorDateOfBirth
EventID
EventName
EventDescription

所以,我想,以避免一个是完全符合上面的扁平化架构类(如果可能)

So, I'm trying to avoid having a class that matches the above "flat" schema entirely (if possible)

是否可能映射此与功能NHibernate?

Is it possibly to map this with Fluent nHibernate?

修改 -
值得一提的是,数据访问将是只读

EDIT-
It's worth mentioning, data access will be read only

推荐答案

正如上述评论表明,它的确是组件的解决了这一点。

As comments above indicated, it was indeed Component that solved this.

随着我的结果映射类下面的几行:

Along the lines of the following in my ResultMap class:

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

这篇关于映射一个平面视图类层次结构中的功能NHibernate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆