Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7773193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:04:36+00:00 2026-06-01T17:04:36+00:00

I have a 1-to-many relationship between the RestorableEnvironment and IBaselineEntity objects: a given RestorableEnvironment

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T17:04:37+00:00Added an answer on June 1, 2026 at 5:04 pm

    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");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have many-to-one mappings working fine, but a one-to-many relationship between locations and location_times
I have a one to many relationship between two tables. The many table contains
I have a one-to-many relationship between two classes for this situation. I have a
I have a one-to-many relationship between Foo and Bar and I cannot perform an
I have a many-to-many relationship between two objects with a join table. I need
Let's say you have a one-to-many relationship between Users and Orders (where one user
I have a many-to-many relationship between People and Departments since one person can be
I have a many-to-many relationship between photos and tags: A photo can have multiple
I have a many-to-many relationship between two tables, let's say Friends and Foods. If
I have a many-to-many relationship between users and groups and I have a table

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.