Hello,
I've been playing around with NHibernate for the past couple days.
I was able to solve most of the problem by looking at the documentation or forum, but I just got one question which I cannot seem to find the answer.
I have 3 tables say tbl_A, tbl_B, and tbl_C.
tbl_A is the base class providing things like first name, last name, email, and so on.
tbl_B extends tbl_A with additional fields (The ID of tbl_B is the ID of tbl_A).
For this inheritance, i used joined-subclass and it was fairly easy.
However, I am stuck with tbl_C.
tbl_C is basically a many-to-many relationship of tbl_A and tbl_B.
To make it more clear, think tbl_A contains all possible users.
tbl_B is sorta like a department leaders which manages multiple group leaders (users in tbl_C).
Each group leader can belong to multiple department leaders (users in tbl_B).
So tbl_C and tbl_B has many-to-many relationship.
I want to make it so that tbl_C still extends tbl_A, but have a collection of users in tbl_B.
in C# it would be something similar to
Code:
public class C : A
{
private IList _parentLeaders = new ArrayList();
public IList ParentLeaders
{
get { return this._parentLeaders; }
}
private C() : A()
{}
}
something similar to that.
This is what I have for tbl_A and tbl_B.
Code:
<class name="User" table="tbl_A">
<id name="UID" column="UID" unsaved-value="0">
<generator class="identity" />
</id>
<property name="FirstName" column="FirstName" />
<property name="LastName" column="LastName" />
<property name="Email" column="Email" />
<property name="UserName" column="UserName" />
<joined-subclass name="DepartmentUser" table="tbl_B">
<key column="UID" />
<property name="SomeOtherProperty" column="SomeOtherProperty" />
</joined-subclass>
</class>
(Modified the class name and etc, so there might be mistakes in here, but for the actual code, it works.)
tbl_C has UID, UserUID (which is in tbl_A) and DepartmentUserUID (which is in tbl_B)
I tried to use <key column="UserUID" />, but it returns WrongClassException or something similar to that.
tbl_C is not exactly ISA tbl_A, but i was wondering if there is any way to group the UserUID in tbl_C and return the collection of tbl_B users?
Any help will be appreciated.
Thanks!
Code: