简体   繁体   中英

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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