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

  • Home
  • SEARCH
  • 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 7195041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:29:56+00:00 2026-05-28T20:29:56+00:00

I am creating a Fluent N hibernate subclass mapping that currently looks something like

  • 0

I am creating a Fluent N hibernate subclass mapping that currently looks something like this:

public class TaskDownloadMap: SubclassMap<TaskDownload>
{
    public TaskDownloadMap()
    {
        Table("TasksDownload");

        Map(x => x.ExtraProperty1, "ExtraProperty1")
            .Nullable();

        Map(x => x.ExtraProperty2, "ExtraProperty2")
            .Nullable();
    }
}

When I try and save one of these entities I get an exception:

Test.TaskRepositoryTest.DeleteTest:
NHibernate.Exceptions.GenericADOException : could not insert: [TaskManager.Entities.TaskDownload#269][SQL: INSERT INTO TasksDownload (ExtraProperty1, ExtraProperty2, Task_id) VALUES (?, ?, ?)]
  ----> System.Data.SqlClient.SqlException : Invalid column name 'Task_id'.

It’s because the Id column I have set on my subclass’s table is named “TaskId”. Is there some to override the default naming scheme that nhibernate is trying to use? I don’t seem to have the ability to specify the “Id” column in the subclass and I can’t find anyone else even talking about it.

The parent mapping looks like this:

public class TaskMap: ClassMap<Task>
{
    public TaskMap()
    {
        Table("Tasks");

        Id(x => x.Id, "Id")
            .GeneratedBy.Identity();

        .
        .
        .

    }
}

Like I said before I am going with the Table-Per-Subclass strategy so these are 2 different tables. I can change the key on my TasksDownload table to be “Task_id” but I’d rather just be able to specify that it’s “TaskId” in my mapping so I can keep to my naming convention.

  • 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-28T20:29:57+00:00Added an answer on May 28, 2026 at 8:29 pm

    You cannot configure the Subclass id’s with the fluent API because it’s handled by the built in mapping convetions. But you can write a custom convention (with some extra acceptance if required).
    A sample solution:

    public class JoinedSubclassIdConvention : IJoinedSubclassConvention, 
         IJoinedSubclassConventionAcceptance
    {
        public void Apply(IJoinedSubclassInstance instance)
        {
             instance.Key.Column(instance.EntityType.BaseType.Name + "Id");
        }
    
        public void Accept(IAcceptanceCriteria<IJoinedSubclassInspector> criteria)
        {
            criteria.Expect(x => x.EntityType == typeof(TaskDownload));
        }
    }
    

    Then you add your convetion to the configuration:

    Fluently.Configure()
        //...
        .Mappings(m =>
            {
                m.FluentMappings
                //...
                .Conventions.Add<JoinedSubclassIdConvention>();
            });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class generated from a WSDL that has a bunch of public
I have this administration site that is using (Fluent) NHibernate for data access. As
I'm Creating a WCF Web Service and mapping my domain model using Fluent Nhibernate
I've got a problem with fluent nhibernate table per class hierarchy mapping. I've got
Is there some kind of a shorthand fluent interface for creating a parameters dictionary
Creating Traversals for Binary Search Tree with Recursion. void inOrder(void (*inOrderPtr)(T&)) { if(this->left !=
Creating liquid layouts is an immense pain. Now, I totally understand that tables should
(creating a separate question after comments on this: Javascript redeclared global variable overrides old
I have a database that I'm running several applications from. I like to separate
I have a class that inherits a base class to which another class has

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.