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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:32:47+00:00 2026-06-08T04:32:47+00:00

The mapping on foreign key are made with the wrong name. Why? Here’s my

  • 0

The mapping on foreign key are made with the wrong name. Why?

Here’s my classes:

The order of the properties seems to be important:

public class Person
{
  public virtual Person Mother { get; set; }
  public virtual IList<Item> Items { get; set; }
  public virtual Person Father { get; set; }
}
public class Item
{
  public virtual string Name { get; set; }
}

Here’s the mapping with Fluent Nhibernate

AutoMap.AssemblyOf<Person>(new CustomAutomappingConfiguration())

When I look to the database, the foreign key in the table seems to be the name of the first property with the type Person after the property Items. Here’s the SQL generated to create the table:

CREATE TABLE "Item" (Id  integer primary key autoincrement
    , Name TEXT
    , Father_id BIGINT
    , constraint FKC57C4A2B4586680 foreign key (Father_id) references Patient)

Thank you in advance for your help 😉

  • 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-08T04:32:50+00:00Added an answer on June 8, 2026 at 4:32 am

    The solution I’ve found is to override the configuraton like this:

    AutoMap.AssemblyOf<Person>(new CustomAutomappingConfiguration())
        .Override<Person>(m => m.HasMany<Item>(x => x.Items).KeyColumn("Patient_Id"))
    

    Does exist any solution to let the auto mapping work seamlessly? And how Fluent nHibernate works to choose the name of the foreign key’s column?

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

Sidebar

Related Questions

For following class mapping: <class name=Person table=Person discriminator-value=null> <id name=ID column=ID > <generator class=identity/>
I have NH mapping public class TblContentMap : ClassMap<TblContent> { public TblContentMap() { Table(tbl_content);
My filter mapping in web.xml is as follows: <filter> <filter-name>LoginCheckFilter</filter-name> <filter-class>com.tutorial.filter.LoginCheckFilter</filter-class> </filter> <filter-mapping> <filter-name>LoginCheckFilter</filter-name>
I have the following LINQ to SQL EF classes: with the foreign key relationship
Assume the following entity classes: public class Player { public virtual int ID {
[Table(Table1)] public class Entity1 { [Key, ForeignKey(entity1)] public int ID{get;set;} public virtual Entity2 entity2{get;set;}
I have a Website table that has a foreign key to a Client table.
I have to map two simple table with a foreign key relationship. One of
Deleting Entity in Entity Model gives Foreign Key errors Error 92 Error 3013: Problem
I have a question about how to map a foreign key ID with NHibernate

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.