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 359093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T12:21:40+00:00 2026-05-12T12:21:40+00:00

I have an entity like: public class Employee { public int ID { get;

  • 0

I have an entity like:

public class Employee
{
    public int ID { get; set; }
    public IAccountManager AccountManager { get; set; }
    ...
}

I also have a mapping defined for “DefaultAccountManager” – a concrete implementation of IAccountManager. When mapping the above “Employee” entity, how do I tell NHibernate to persist/load the AccountManager property using the mapping defined in “DefaultAccountManager”?

Edit:
Actually if I could setup a mapping for IAccountManager so that NHibernate could just infer which implementer to load/persist that would be even better. I’d rather not have to break polymorphism by forcing all implementers to use the same mapping.

  • 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-05-12T12:21:41+00:00Added an answer on May 12, 2026 at 12:21 pm

    I did find an answer to this one. I’m a little hazy on the details, as it was a few months ago, but the following was the jist of the solution:

    • Create a table for each implementation of IAccountManager that has mappings.
    • Make sure your DB is setup to use the HiLo id algorithm.
    • Use union-subclasses in your mappings

    Union-subclasses would look something like this:

    <class name="IAccountManager" abstract="true">
      <id name="ID" column="ID" type="Int32">
        <generator class="hilo"/>
      </id>
      <union-subclass name="DefaultAccountManager" table="DefaultAccountManager"
          proxy="IAccountManager">
        <property name="FirstName" type="String"/>
        <property name="LastName" type="String"/>
      </union-subclass>
      ... more implementations
    </class>
    

    Note the attribute “name” on union-subclass. This should be unique for (and match) each implementation of IAccountManager.

    Also, the ID, instead of being unique to each table, will be unique to all IAccountManagers (by leveraging hilo).

    When NHibernate sees an IAccountManager entity, it will use the instance’s concrete type and the union-subclass definitions to figure out the correct table.

    Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.