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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:20:37+00:00 2026-06-18T02:20:37+00:00

I have an Nhibernate mapping from my database to my c# code. I am

  • 0

I have an Nhibernate mapping from my database to my c# code. I am going to lay out a simple representation of the structure.

class ItemHolder
{
    public virtual ICollection<Item> ItemCollection {get;set;}
}

class Item
{
    public virtual int Id{get;set;}
    public virtual string SomeValue{get;set;}
}    

And my NHibernate mappings

<class name="ItemHolder" table ="ItemHolders">
    ...
    <set name="ItemCollection" cascade="all-delete-orphan" inverse="true">
        <key column="ItemHolder"/>
        <one-to-many class="Item"/>
    </set>
</class>

<class name="Item" table="Items">
    <id name="ID" generator="native"/>
    ...
    <many-to-one name="ItemHolder" class="ItemHolder"/>
</class>

All this works fine and when I execute the following code I retrieve everything as expected.

bindingSource.DataSource = ISession.CreateQuery("select ih from ItemHolder as ih " +
            "left join fetch ih.ItemCollection")
            .SetResultTransformer(new DistinctRootEntityResultTransformer())
            .List<Item>();

As in I populate the binding source with ItemHolders each with a fully populated ItemCollection full of Items.

HOWEVER

when I add a joined sub class to Item for use elsewhere in my program like this:

class DerivedItem : Item
{
}

with the addition to the Item mapping of a joined subclass.

<class name="Item" table="Items">
    <id name="ID" generator="native"/>
    ...
    <many-to-one name="ItemHolder" class="ItemHolder"/>
    <joined-subclass name="DerivedItem" table="DerivedItems" extends="Item">
        <key column="ID"/>
    </joined-subclass>
</class>

Now things get funny. I can retrieve my derived items from the derived item table with no problem but when I try to execute the above c# code I get an error.

If I look at ((ItemHolder)bindingSource.Current).ItemCollection then my first item in the collection is mapped to class type Item however the second in the list is not mapped at all causing errors. I can see all its properties in the debugger but no type information.

I have isolated the error so that if I remove the joined-subclass from the Item mapping I have no problems, however I would like to have this capability.

I realise this is quite specific, and I have not given the exact code which may make things difficult to understand but maybe someone has experienced something similar or can spot a mistake in my mappings.

  • 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-18T02:20:38+00:00Added an answer on June 18, 2026 at 2:20 am

    I found out that DerivedItem was also in the Item table, so the Item was being mapped to a derived item causing problems when adding to binding sources, as they were of different types.

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

Sidebar

Related Questions

I have the following entity and Fluent NHibernate mapping: public class Advertiser { public
lets's say I have: // all objects have valid mapping to database public class
My database is being driven by my NHibernate mapping files. I have a Category
I have a very simple Mapping I'm trying to do. I'm following the NHibernate
I am using nhibernate and i have code like this in the mapping area:
Good Day, I have a Hibernate mapping that looks something like this: public class
I have a problem with nhibernate mapping. I use the nhibernate 3.2 mapping by
I'm new to NHibernate and trying to create my first mapping. I have created
I'm using Fluent NHibernate, and auto-mapping the classes. I have a computed property in
I have a Hibernate mapping that looks something like this: <class name=MyEntity> <set name=scalarSet

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.