Q:

NHibernate: Persist Reference to Interface with Multiple Contrete Classes

I have a 1-to-many relationship between the RestorableEnvironment and IBaselineEntity objects: a given RestorableEnvironment will have one and only one IBaselineEntityobject, but each IBaselineEntity object may be tied to 0-n RestorableEnvironment objects. However, IBaselineEntity is implemented in one of two ways: via a file or via a database. My classes are (generally) like:
public interface IBaselineEntity
{
    BaselineImage BuildImage();
    //Remainder of interface
}

public class BaselineFile : IBaseline
{
    //implementation
}

public class BaselineDatabase : IBaseline
{
    //implementation
}

public class RestorableEnvironment
{
    public IBaselineEntity BaselineEntity { get; set; }
    //Remainder of class
}

NHibernate needs the concrete implementation of the IBaselineEntity in the references statement. To handle that, I have updated RestorableEnvironment to:
public class RestorableEnvironment
{
    public IBaselineEntity BaselineEntity
    {
        get { return BaselineDatabase ?? BaselineFile; }
        set
        {
            BaselineFile = value as BaselineFile;
            BaselineDatabase = value as BaselineDatabase;
        }
    }

    private BaselineFile _baselineFile;
    public BaselineFile BaselineFile
    {
        get { return _baselineFile; }
        protected set
        {
            _baselineFile = value;
            if (value != null)
                BaselineDatabase = null;
        }
    }

    private BaselineDatabase _baselineDatabase;
    public BaselineDatabase BaselineDatabase 
    {
        get { return _baselineDatabase; }
        protected set
        {
            _baselineDatabase= value;
            if (value != null)
                BaselineFile = null;
        }
    }

    // Remainder of class
}

Now that I have concrete classes, I can now map in NHibernate, but this feels like a hack. Are there any suggestions for an improvement?

A:

map it as any reference
using fluentmapping
// ClassMap<RestorableEnvironment>
RestorableEnvironmentMap()
{
    ReferenceAny(e => e.BaselineEntity)
        .EntityIdentifierColumn("entirtyid")
        .EntityTypeColumn("entitytype")
        .IdentityType<int>()
        .MetaType<string>()
        .AddMetaValue<E1>("e1")
        .AddMetaValue<E2>("e2");
}

