Dear NHibernate-user
I have Categories that has a Strongly Typed Collection of bsSubcategory. Each item in this collection could either be bsRegularSubcategory or bsPackage. Both inherited classes should always have an Id, PositionInCat, Title and Subtitle.
Code:
Public Class bsCategory
Private mId As Integer
Private mSubcategories As IList(Of bsSubcategory)
----------------------------------------------------
Public MustInherit Class bsSubcategory
Private mId As Integer
Private mPositionInCat As Integer
Private mTitle As String
Private mSubtitle As String
----------------------------------------------------
Public Class bsRegularSubcategory
Inherits bsSubcategory
----------------------------------------------------
Public Class bsPackage
Inherits bsSubcategory
The mapping is as following. At this moment I can attach a collection of bsRegularSubcategory OR a collection of bsPackage, but not both at the same time in one collection....preferrably ordered by PositionInCat throughout both inherited types.
My mapping files are as following (at this moment only items of bsRegularSubcategory are added to the collection):
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="NHibernateProject.bsCategory, NHibernateProject" table="TBL_CATEGORIES">
<id name="Id" column="Cat_Id" type="Int32">
<generator class="assigned" />
</id>
<property name="Name" column="Cat_Name" type="String" length="50"/>
<property name="PositionInGrp" column="Cat_PositionInGrp" type="Int32"/>
<bag name="Subcategories" order-by="SubCat_PositionInCat" table="TBL_SUBCATEGORIES">
<key column="SubCat_Cat_Id" />
<many-to-many class="NHibernateProject.bsRegularSubcategory, NHibernateProject" column="SubCat_Id"/>
</bag>
</class>
</hibernate-mapping>
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="NHibernateProject.bsRegularSubcategory, NHibernateProject" table="TBL_SUBCATEGORIES" polymorphism="implicit">
<id name="Id" column="SubCat_Id" type="Int32">
<generator class="assigned" />
</id>
<property name="PositionInCat" column="SubCat_PositionInCat" type="Int32"/>
<property name="Title" column="SubCat_Title" type="String" length="50"/>
<property name="Subtitle" column="SubCat_Subtitle" type="String" length="50"/>
</class>
<class name="NHibernateProject.bsPackage, NHibernateProject" table="TBL_PACKAGES" polymorphism="implicit">
<id name="Id" column="Pac_Id" type="Int32">
<generator class="assigned" />
</id>
<property name="PositionInCat" column="Pac_PositionInCat" type="Int32"/>
<property name="Title" column="Pac_Title" type="String" length="50"/>
<property name="Subtitle" column="Pac_Subtitle" type="String" length="50"/>
</class>
</hibernate-mapping>
I made a screenshot of what resides in my database at this moment. Both tables TBL_PACKAGES and TBL-SUBCATEGORIES contain deviating columns, but showing this could only make it more confusing:
The result should be as following, ordered within Category with Id = 205:
- Regular Subcategory-Id: 196
- Package-Id: 2
- Regular Subcategory-Id: 197
Could anyone help me out, please? I started to like NHibernate, but now I am stuck again.
Thanks in advance. Bennieke.