NHibernate Free Polymorphic Mapping Issues

I'm having trouble displaying the following script in Fluent Nhibernate using the Table Per Concrete class:

Let's say I have the following class definitions:

public class Reading { .... }

public class CarReading : Reading { .... }

public class TruckReading : Reading { .... }

public class Alert 
{
    ....
    public virtual Reading AReading { get; set; }
}

So my question is how to create a mapping class for Alert if it has a one-to-one relationship with the reading class (maybe either reading a truck or reading a car) and instruct nhibernate to find out which table to load data from ( Truck table or CarReading table)

public class AlertMap : ClassMap<Alert>
{
    ....
    HasOne(x => x.AReading);
}

If someone can point me in the right direction that would be very appreciated.

Thanks.

+1
source share
1
public class AlertMap : ClassMap<Alert>
{
    ....
    ReferenceAny(x => x.AReading)
        .EntityIdentifierColumn("readingid")
        .EntityTypeColumn("readingtype")
        .IdentityType<int>()
        .AddMetaValue<CarReading>("car")
        .AddMetaValue<TruckReading>("truck");
}
0

All Articles