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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T05:59:34+00:00 2026-05-25T05:59:34+00:00

I’m having difficulty mapping a database using Fluent NHibernate. The database I’m working on

  • 0

I’m having difficulty mapping a database using Fluent NHibernate. The database I’m working on is brownfield and some of the relationships are poorly implemented.

The mapping I’m trying to do is described by the following tables:

+----------+ +----------+ +---------------+  +-------------------+
| ToolA    | | ToolB    | | ToolPurpose   |  | ToolInstruction   |
+==========+ +==========+ +===============+  +===================+
| ToolA_Id | | ToolB_Id | | Purpose_Id    |  | ToolInstruction_Id|
| Name     | | Name     | | ToolA_Id      |  | Purpose_Id        |
+----------+ +----------+ | ToolB_Id      |  | Instruction       |
                          | Purpose       |  +-------------------+
                          +---------------+

What I’m looking to do is to map the table ToolA with the table ToolInstruction to get a class such as:

public class ToolA
{
    public virtual int _ToolA_id { get; set; }
    public virtual string _Name { get; set; }
    public virtual string _Instruction { get; set; }
}

OR

public class ToolA
{
    public virtual int _ToolA_id { get; set; }
    public virtual string _Name { get; set; }
    public virtual ToolInstruction _ToolInstruction{ get; set; }
}

public class ToolInstruction
{
    public virtual string _Instruction { get; set; }
}

What I think is causing me difficulty is that the ToolPurpose table has a row for every ToolA and ToolB entry such that for a ToolA entry the ToolB_Id is null and vice versa.

For example:

+--------------------------------------------------+
|Purpose_Id | ToolA_Id | ToolB_Id | Purpose        |
|===================================================
|1          | 1        | null     | "purpose here" |
|2          | null     | 1        | "purpose here" |
+--------------------------------------------------+

I’ve tried a few approaches to this and they have shown signs of working when using the PersistenceSpecification.VerifyTheMappings() method but not when I’ve tried pulling data from a backup database because I start running into null reference exceptions.

I’ve tried mapping ToolPurpose as a linker class and I’ve tried mapping it by using the Join method in the ToolA mapping class. I’ve also alternated between using HasOne and HasMany to see which was suitable.

I’m hoping someone can point me in the right direction by laying out how they would do it or if they see any problems in terms of how I’m approaching it.

  • 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-25T05:59:35+00:00Added an answer on May 25, 2026 at 5:59 am

    I’m working without any documentation for the database I’m mapping and it turns out this was where my difficulty arose. The ToolPurpose to ToolA relationship is actually a many to one relationship such that each tool has multiple purposes and the ToolPurpose to ToolInstruction relationship is also a many to one relationship such that each purpose can have multiple instructions related to it.

    This means a straight forward HasMany() <-> References() mappings can be used to link the ToolA, ToolPurpose and ToolInstruction tables together. The null values in the ToolPurpose table do not affect the mappings in this way.

    I should have mentioned in my openbing post that I’m just extracting and not updating or saving to the database so I do not need a complete mapping of the tables so I don’t have to map ToolB.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.