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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:45:04+00:00 2026-05-16T07:45:04+00:00

I have two tables in a legacy database… tblParentTable (int id, string specialIdentifier, …)

  • 0

I have two tables in a legacy database…

tblParentTable (int id, string specialIdentifier, ...)
tblChildTable (int id, string specialIdentifier, ...)

As you can see, an auto-incrementing int id has been added, but the child table is joined using the old string primary key (in fact, specialIdentifier is the primary key of tblParentTable, and the primary and foreign key on tblChildTable).

So I have created domain objects and Fluent NHibernate maps, but because of this odd schema, NHibernate thinks that it needs to save the tblChildTable record first, before it saves tblParentTable – this results in a foreign key constraint error.

How can I hint to NHibernate that tblParentTable is the parent and needs to be saved first?

Here is are the mappings…

public ParentMap()
{
    Table("tblParentTable");
    Id(x => x.Id).Column("id");
    Map(x => x.SpecialIdentifier);
    References(x => x.Child).Column("specialIdentifier");
}

public ChildMap()
{
    Table("tblChildTable");
    Id(x => x.Id).Column("id");
    Map(x => x.SpecialIdentifier);
    References(x => x.Child).Column("specialIdentifier");
}

Please feel free to ask for more information if you think I am missing something important.

Thanks

  • 1 1 Answer
  • 3 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-16T07:45:05+00:00Added an answer on May 16, 2026 at 7:45 am

    If you are looking to do this kind of mapping in Fluent NHibernate, there is a good article on it here:

    http://wiki.fluentnhibernate.org/Fluent_mapping

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

Sidebar

Related Questions

I have two tables in my legacy database Purchases Id int(PK) name varchar(50) MasterAccount
I have two tables in a legacy database that I need to map using
So I'm connecting to a legacy database. I have two tables, Sites and States
I have two tables (A and G) in an Oracle database that can be
I have two tables in my MySQL database, one is a library of all
I have a legacy data base and a relation one-to-one between two tables. The
I have two fields: string date1 = 04/26/10; string date2 = 04/25/10; How can
I have two tables inside a database. One stores unique userNames and a unique
I have two different existing Database design's in the legacy apps I inherited. On
In a legacy database I have to work with nested tables that are associated

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.