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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:15:29+00:00 2026-05-23T22:15:29+00:00

I have a legacy database that uses a table per class hierarchy inheritance strategy

  • 0

I have a legacy database that uses a table per class hierarchy inheritance strategy that uses two database columns as discriminators, usetype and formattype. UseType gives you the top level, formattype the second.

Essentially I would like to be able to populate a class hierarchy like:

public abstract class Unknown {}

public abstract class Animal : Unknown { }
public class Lion : Animal {}
public class Lamb : Animal {}

public class Mineral : Unknown { }

public abstract class Vegetable : Unknown {}

public class Rose : Vegetable { }
public class Cabbage : Vegetable {}

From data like:

| UseType   | FormatType |
--------------------------
| Animal    | Lion       |
| Animal    | Lamb       |
| Mineral   | null       |
| Vegetable | Rose       |
| Vegetable | Cabbage    |

I thought I could user Fluent mappings like:

public sealed class UnknownMap : ClassMap<Unknown>
{
    public UnknownMap()
    {
        DiscriminateSubClassesOnColumn("UseType");
    }
}

public sealed class AnimalMap : SubclassMap<Animal>
{
    public AnimalMap()
    {
        DiscriminatorValue("Animal");
        DiscriminateSubClassesOnColumn("FormatType");
    }
}

public sealed class LionMap : SubclassMap<Lion>
{
    public LionMap()
    {
        DiscriminatorValue("Lion");
    }
}

public sealed class LambMap : SubclassMap<Lamb>
{
    public LambMap()
    {
        DiscriminatorValue("Lamb");
    }
}

public sealed class MineralMap : SubclassMap<Mineral>
{
    public MineralMap()
    {
        DiscriminatorValue("Mineral");
    }
}

public sealed class VegetableMap : SubclassMap<Vegetable>
{
    public VegetableMap()
    {
        DiscriminatorValue("Vegetable");
        DiscriminateSubClassesOnColumn("FormatType");
    }
}


public sealed class RoseMap : SubclassMap<Rose>
{
    public RoseMap()
    {
        DiscriminatorValue("Rose");
    }
}

public sealed class CabbageMap : SubclassMap<Cabbage>
{
    public CabbageMap()
    {
        DiscriminatorValue("Cabbage");
    }
}

But unfortunately DiscriminateSubClassesOnColumn isn’t supported in SubclassMap.

According to the Fluent NHibernate Wiki, multi column discriminators are supported through the use of a custom sql statement.

Unfortunately, I have to support a rather large number of subclasses, and I’d really prefer to use something that’s compiled with the code. After all, that’s why I’m using Fluent NHibernate in the first place.

  • 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-23T22:15:30+00:00Added an answer on May 23, 2026 at 10:15 pm

    2 options for using string concatenation come to my mind:

    • generate a storedProcedure for stringconcatenation which can be reimplemented in each DB-System and use a formula to call it

    • make the classmap UnknownMap database aware

      public UnknownMap()
      {
          string formula;
          switch (Configuration.GetDbType())
          {
              case DBType.SQLServer:
                  formula = "GROUP_CONCAT(UseType, FormatType´)";
                  break;
              ...
          }
      
          DiscriminateSubClassesOnColumn("")
              .Formula(formula);
      }
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a legacy database that uses strings as primary keys. I want to
I'm working on a legacy database that is complete non-sense. I have a table
As the post title implies, I have a legacy database (not sure if that
I currently have a database that gets updated from a legacy application. I'd like
In a legacy database (SQL Server 2000), we have a clustered index that looks
I have a legacy VB6 application that uploads file attachments to a database BLOB
I have a table which has essentially boolean values in a legacy database. The
I have two data sources: a legacy one (web service) and a database one.
I currently have a legacy system that uses SPs exclusively for access to the
I'm writing a C# frontend to a legacy database that uses VB6 Rnd() and

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.