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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:20:32+00:00 2026-05-28T01:20:32+00:00

I have a Base class and two childs (A:Base and B:Base), and I want

  • 0

I have a Base class and two childs (A:Base and B:Base), and I want to map them to two tables (table A and table B). Is that possible in Fluent NHibernate? So I have:

public class Base
{
    public virtual int Id {get;set;}
    public virtual int IndexIn {get;set;}
    public virtual Product Product {get;set;}
}

public class A : Base
{
    public virtual string Value {get;set;}
}

public class B : Base
{
    public virtual int Value {get;set;}
    public virtual IList<Sequence> Sequences {get;set;}
}

My mapping is:

public class BaseMap : ClassMap<Base>
{
     public BaseMap()
     {
        Id(x => x.Id);
        Map(x => x.IndexIn);
        References(x => x.Product);
     }
}

public class AMap : SubclassMap<A>
{
     public AMap()
     {
         Map(x => x.Value);
     }
}
public class BMap : SubclassMap<B>
{
     public BMap()
     {
         Map(x => x.Value);
         HasMany(x => x.Sequences);
     }
}

But in that case it creates three tables (A, B and Base). That’s nice, but I need to reduce number of tables, so I am ok to have Base’s fields in both A and B table. Generally I want to simply map A and B as normal classes (without using inheritance), but I need to be able to add some other class, where I can have property:

public virtual IList<Base> ListofAandB {get;set;}

If I remove BaseMap definition and just map A and B as ClassMap<> I receive error “Cannot find map definition for Base” if I try to use the property that is written above.

  • 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-28T01:20:32+00:00Added an answer on May 28, 2026 at 1:20 am

    You won’t be able to map your ListOfAAndB property if your inheritance is present only in your code and not in your database model. To have NHibernate map this property as it is defined, you are going to need a Base table in your database.

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

Sidebar

Related Questions

I have a very simple scenario, using NHibernate: one abstract base class animal; two
Let's say we have these two classes: public class Base { public static int
I have a question, here are two classes below: class Base{ public: virtual void
I have a virtual base class and two classes that implement the various methods.
I have a relationship between two base classes: public abstract class RecruiterBase<T> { //
If I have a base class and two derived classes, and I want to
I have a Base Class with two constructors, requiring a parameter: public abstract class
I have two tables with a join table between them: Parent: Pages Child: Things
I have a base class that I inherit from that has two zero to
I have a base class that has a virtual property: public virtual string Name

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.