I have the following mapping:
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="MyData.Department, MyData" table="departments">
<id name="Id" column="id" type="integer">
<generator class="increment" />
</id>
<property name="Name" column="name"></property>
<set name="People" table="department_people" lazy="true">
<key column="department_id"/>
<many-to-many class="MyData.Person, MyData" column="person_id" />
</set>
</class>
</hibernate-mapping>
I would to simply have code that looks like:
Code:
foreach (Person person in mydept.People)
{
Console.WriteLine(person.Name);
}
and have the list of people come out in alphabetical order.
I was wondering what the best option for this is. So far I thought of the following.
1) order-by - Unless I'm mistaken, this doesn't work since the name column isn't in the department_people table. Instead of department_people I could create a view which is the department_people table with the person's name as another column. So I can order-by the name. So far this is a read-only project so I'm not familiar enough with NHibernate to determine how this might negatively impact saving.
2) Adding another property to my Department class which sorts and returns a new ISet of people.
3) HQL query - I don't have the joining table (department_people) in hibernate so I don't know how I can join this.
Thanks,
Andy