Hi,

I have a problem with setting a certain ordering for bag collections
in my mapping file.
Let's say I have an Employee class and a Project class. They have a
many-to-many relationship; an Employee can be assigned to multiple
projects and a project team consists of multiple employees. I also
made a ProjectAssignment class to represent this.

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="DomainModel" namespace="DomainModel">
  <class name="ProjectAssignment" table="tblProjectAssignment">
    <composite-id>
      <key-many-to-one name="Employee" class="Employee"
column="EmployeeID" />
      <key-many-to-one name="Project" class="Project"
column="ProjectID" />
    </composite-id>
  </class>
</hibernate-mapping>

The Project class has an Assignments collection to reflect the
employees that are assigned to the project.
I'd like to order this collection by the last name of the employee.

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="DomainModel" namespace="DomainModel">
  <class name="Project" table="tblProject">
    <id name="ID" column="ProjectID">
      <generator class="identity" />
    </id>
    ....
    <bag name="Assignments" cascade="none" order-
by="Employee.LastName" >
      <key column="ProjectID" />
      <one-to-many class="ProjectAssignment" />
    </bag>
  </class>
</hibernate-mapping>

This isn't going to work because the Employee table is not in the SQL
that is executed when the Assignments property is called.
NHibernate generates a query that only selects records from the
tblProjectAssignment table for a certain ProjectID without any joins.
What's the best way to solve this? Is there a way in the mapping of
the collection that tells NHibernate to join the Employee table along?
Surely I could do the ordering of the list afterwards in my
application, but preferably I'd let NHibernate perform this default
ordering.

Regards,
Nils

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to