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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:51:58+00:00 2026-05-26T02:51:58+00:00

Consider the following class hierarchy: public abstract class Entity { public virtual int Id

  • 0

Consider the following class hierarchy:

public abstract class Entity
{
    public virtual int Id { get; private set; }
}

public class ConfiguredBlockEntity : Entity
{
    public virtual ScheduledGreetingEntity ScheduledGreeting { get; set; }
}

public abstract class ConfiguredVariableEditableBlockEntity
    : ConfiguredBlockEntity
{
    public virtual VariableEditableBlockEntity TemplateBlock { get; set; }
}

public class ConfiguredPhoneNumberBlockEntity
    : ConfiguredVariableEditableBlockEntity
{
    public virtual string PhoneNumber { get; set; }
}

I am using the automapping feature of Fluent NHibernate.
This creates the following table structure:

create table "BlockEntity" (
    Id INT IDENTITY NOT NULL,
   ExecutionOrder INT null,
   Name NVARCHAR(255) null,
   BlockType NVARCHAR(255) null,
   GreetingId INT null,
   primary key (Id)
);

create table "ConfiguredBlockEntity" (
    Id INT IDENTITY NOT NULL,
   ScheduledGreetingId INT null,
   primary key (Id)
);

create table ConfiguredPhoneNumberBlockEntity (
    ConfiguredVariableEditableBlockId INT not null,
   PhoneNumber NVARCHAR(255) null,
   VariableEditableBlockId INT null,
   primary key (ConfiguredVariableEditableBlockId)
);

alter table ConfiguredPhoneNumberBlockEntity 
    add constraint FK87F9EFC9BB9A4B52 
    foreign key (ConfiguredVariableEditableBlockId) 
    references "ConfiguredBlockEntity";

There are some problems with this result:

  1. The table ConfiguredPhoneNumberBlockEntity has one column that is primary key and foreign key to the base class in one (column ConfiguredVariableEditableBlockId. This looks strange and doesn’t conform to how I normally design my tables. If I would have designed the table by hand, it would have an Id column that is the PK and an ConfiguredBlockId columnt that is the FK. Can I change this somehow with fluent or automapping?
  2. The PK/FK column is named ConfiguredVariableEditableBlockId, but there exists no table ConfiguredVariableEditableBlock, because it was an abstract base class and its property has been incorporated into ConfiguredPhoneNumberBlockEntity table. This column references the table ConfiguredBlockEntity and thus should be named accordingly. How to fix this in fluent or automapping?
  • 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-26T02:51:59+00:00Added an answer on May 26, 2026 at 2:51 am
    1. an inheritance table doesnt need an extra Id column, its never read alone or by id. Normally its joined with the baseclass-table. Therefor FNH defaults to this design. You can enforce your design for example with FluentMappings with a hidden Property Id as Readonly (additional work for no value).

    2. class MyJoinedSubclassConvention : IJoinedSubclassConvention,
                                         IJoinedSubclassConventionAcceptance
      {
          public void Accept(IAcceptanceCriteria<IJoinedSubclassInspector> criteria)
          {
              criteria.Expect(x => x.Name == "ConfiguredPhoneNumberBlockEntity");
          }
      
          public void Apply(IJoinedSubclassInstance instance)
          {
              instance.Key.Column("baseclassId");
          }
      }
      

    Edit: or more general

    class MyJoinedSubclassConvention : IJoinedSubclassConvention
    {
        public void Apply(IJoinedSubclassInstance instance)
        {
            Type basetype = instance.Extends;
            while (basetype.IsAbstract)
            {
                basetype = basetype.BaseType;
            }
            instance.Key.Column(basetype.Name + "Id");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following class public class Class1 { public int A { get; set;
consider the following class and struct public class Entity { public IdType Id {get;set;}
Consider the following class hierarchy: public class Foo { public string Name { get;
consider the following class: class Order { int OrderId {get; set;} int CustomerId {get;
Consider the following code: class A { public: virtual void f() throw ( int
Let's consider the following simplified Resource hierarchy: public abstract class Resource { static public
Consider the following class: public class ComponentA { public ComponentB ComponentB { get; set;
Consider the following set of classes/Interfaces: class IFish{ public: virtual void eat() = 0;
consider the following class: public class ShortName { public string ValueString { get; set;
Consider the following class: public class MyIntSet { private List<int> _list = new List<int>();

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.