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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:22:27+00:00 2026-06-10T11:22:27+00:00

I have two tables which share common fields. Rather than re-map all of these

  • 0

I have two tables which share common fields. Rather than re-map all of these I would like to have a base class with the common fields. For POCO this is simple:

class Base
{
   public string commonField {get;set;}
}
class Derived : Base
{
   public string specificField {get;set;}
}
class OtherDerived : Base
{
   public string specificOtherField {get;set;}
}

Note that there is no such thing as a table for “base”. It just holds lots of common fields shared among several tables. Yes, I know this is not well normalized, but it’s what I have to work with.

My question is – is there a way to implement this in fluent nHibernate without having to duplicate the code that maps those common properties?

  • 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-10T11:22:29+00:00Added an answer on June 10, 2026 at 11:22 am

    You can inherit from ClassMap to do this. I would do something like the following:

    public class BaseMap<T> : ClassMap<T> where T : Base
    {
        public BaseMap()
        {
            Map(x => x.commonField, "COMMON_FIELD");
        }
    }
    
    public class DerivedMap : BaseMap<Derived>
    {
        public DerivedMap()
        {
            Table("DERIVED_TABLE");
            Polymorphism.Explicit();  //You may want to use this in your case.
            Map(x => x.DerivedField, "DERIVED_FIELD");
        }
    }
    

    Notice the Polymorphism.Explicit(); above. In your case I think you are going to want this.

    http://www.nhforge.org/doc/nh/en/#mapping-declaration-class

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

Sidebar

Related Questions

I have two tables, Users and People, both of which share a common attribute,
I have two tables which looks something like this Table Queue int ID; string
I have two tables which look like the following tools : id | part
I have two tables which look like this: T1: T1ID | Date | Time
I have two tables which looks like this: News: (ID, Title, TagID) Tags: (ID,
I have two related classes which share a common interface and are both stored
I have 2 tables which share a common table of types The type table
I have two tables which share primary keys. I designed poorly, and it turns
I have two tables which are used to store details of different types of
I have two tables which I want to join together using a left outer

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.