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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:58:32+00:00 2026-05-16T05:58:32+00:00

I am trying to map a new domain model to a fixed-schema legacy database

  • 0

I am trying to map a new domain model to a fixed-schema legacy database and am stuck on how to do a certain type of mapping. Here’s a distilation of my problem.

There are types of Workers. For example an HourlyWorker and a SalariedWorker.

The data for an HourlyWorker is stored in the WORKERS table and the HOURLY_WORKERS table with a standard foreign key relation between the two of WORKERS.PK_WORKERS = HOURLY_WORKERS.FK_WORKERS.

The “Id” of the HourlyWorker from NHibernate’s point of view is mapped to WORKERS.PK_WORKERS, which is as it should be.

So far so good.

Now suppose there is an object that applies only to hourly workers.

class Timesheet
  HourlyWorker Owner { get; private set; }

In the legacy database this maps to the TIMESHEETS table in a fairly straightforward manner but with one catch: The foreign-key link to the owner is expressed not through a link to the WORKER table but via a link to the HOURLY_WORKER table. In other words, the foreign key FK_HOURLY_WORKER is a unique identifier but is not pointing at the value that is in NHibernate’s view the primary key.

I cannot simply change the Id HourlyWorker to map to the HOURLY_WORKER table because 70% of the database referencing houry workers uses the primary key from WORKER as the foreign key Id.

What are my options for mapping this relationship?

Something that might make this easier: the Owner property is read only – the Timesheet cannot have it’s owner changed. However, when an HourlyWorker is deleted, deletes should cascade to all of their Timesheets.

Finally, please don’t respond with recommendations that I change the database. I know. If you want my client’s phone number so that you can try to convince them that their schema is not the most perfect thing in existence then I can supply it. I have been fighting this fight for months. Also please don’t respond that this indicates that the problem is managerial and not just NHibernate mappings. I know that too. For right now, I just want advice on how to solve the technical problem.

  • 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-16T05:58:32+00:00Added an answer on May 16, 2026 at 5:58 am

    I believe you are looking for the property-ref attribute of the many-to-one element:
    NHibernate docs

    By the way, mapping to a legacy schema is hard – be prepared for some serious pain! On the plus side, you’ll be an NHibernate expert by the time you come out on the other side.

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

Sidebar

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.