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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:03:44+00:00 2026-05-10T23:03:44+00:00

NHibernatians! I have a table [dbo].[Wibble] and another table [dbo].[WibbleExtended]. [Wibble] is the main

  • 0

NHibernatians!

I have a table [dbo].[Wibble] and another table [dbo].[WibbleExtended].

[Wibble] is the main table and [WibbleExtended] is an optional table where some other fields are stored. There are far fewer entries in the [WibbleExtended] table than the main [Wibble] table. I think this was done back in the day to cure some space issues (Wibble has many rows and WibbleExtened has many columns).

The ID for each table is the same and comes from an external source.

I.e.

[dbo].[Wibble].[WibbleId] 

and

[dbo].[WibbleExtended].[WibbleId] 

are identical and is how the two tables relate.

N.B. I can’t change the schema. I’m shoe-horning this onto a legacy system that I have almost no control over.

Searching around it seems that one-to-one mappings are problematic and the prevailing wisdom is to use two many-to-one mappings.

My mappings currently are:

<class name='Wibble' table='Wibble' >    <id name='Id' column='WibbleId' type='Int32'>       <generator class='assigned'/>    </id>     <many-to-one name='WibbleExtended' class='WibbleExtended' column='WibbleId' not-null='false' cascade='all'/> </class> 

And

<class name='WibbleExtended' table='WibbleExtended' >    <id name='Id' column='WibbleId' type='Int32'>         <generator class='assigned' />    </id>     <many-to-one name='Wibble' class='Wibble' column='WibbleId' not-null='true' />       </class> 

The problem with this is I’m getting errors such as

System.IndexOutOfRangeException: Invalid index n for this SqlParameterCollection with Count=n. 

I’ve looked around and this does look like the correct strategy, it’s just falling at the final hurdle.

Is the problem the id generator? Other aspect of the mapping?

Free mince pie for the correct answer.

EDIT: Ok – here’s what I did to solve this via @James Gregory.

  1. Moved the unit tests from the WibbleExtended tests to the Wibble test class and made the necessary modifications.

  2. Added the following to the Wibble.hbm.xml

    <join table='WibbleExtended' optional='true'>      <key column='WibbleId'/>      <property name='Blah1' column='Blah1' type='String' length='2000' not-null='false' />      <property name='Blah2' column='Blah2' type='String' length='1000' not-null='false' />     </join> 
  3. Added the corresponding properties to the Wibble POCO.

  4. Deleted all code relating to WibbleExtended.

  5. Run tests, all passed, checked in. Build passed. Went for an xmas beer (hence it’s been a couple of days before I updated this! :-))

  • 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. 2026-05-10T23:03:44+00:00Added an answer on May 10, 2026 at 11:03 pm

    Have you considered using the Join element that was introduced in NHibernate 2.0? This element allows you to join multiple tables to form one entity; that relationship can also be optional.

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

Sidebar

Related Questions

i want to get data from sql server database in asp.net using NHibernate. what

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.