Mapping a flat view to class hierarchy in fluent nHibernate

本小妞迷上赌 提交于 2019-12-10 15:45:23

问题


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

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)

Is it possibly to map this with Fluent nHibernate?

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


回答1:


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


来源:https://stackoverflow.com/questions/11206964/mapping-a-flat-view-to-class-hierarchy-in-fluent-nhibernate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!