I can get my head around how to do this query with NHibernate.
I ideally need to take the ICriteron Object approach rather than them using named query's, because i want to combine the expression with other expressions.
I have 2 entities 'DirectoryEntry' and 'Tow', each DirectoryEntry can have a relationship with zero or more Tows.
What i need is an expression that returns all DirectoryEntrys who have a certain Tow. How do i query this relation ship?
Here are my mapping docs:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="careers.core.domain.intdir.DirectoryEntry,careers.core" lazy="false" table="idInternationalDirectory">
<id name="Id" column="ID" type="Int32" unsaved-value="0">
<generator class="native"/>
</id>
<many-to-one name="Client" class="careers.core.domain.cems.Client,careers.core" column="ClientID"/>
<many-to-one name="Location" class="careers.core.domain.intdir.Location,careers.core" column="HESAID"/>
<property column="Profile" type="String" name="Profile" not-null="true" length="2000" />
<property column="url" type="String" name="Url" not-null="true" length="50" />
<set name="Tows" lazy="false" table="idTowLookup">
<key column="entryID" />
<many-to-many column="TOWID" class="careers.core.domain.intdir.Tow,careers.core" />
</set>
</class>
<query name="DirectoryEntry.Search">from DirectoryEntry de where de.Client.ClientName like ? or de.Profile like ?</query>
<query name="DirectoryEntry.SearchByName">from DirectoryEntry de where de.Client.ClientName like ?</query>
<query name="DirectoryEntry.SearchByProfile">from DirectoryEntry de where de.Profile like ?</query>
<query name="DirectoryEntry.S">from DirectoryEntry de where de.Client.ClientName like ? or de.Profile like ?</query>
</hibernate-mapping>
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="careers.core.domain.intdir.Tow,careers.core" lazy="false" table="csTOW">
<id name="Towid" column="TOWID" type="Int32" unsaved-value="0">
<generator class="native"/>
</id>
<property column="TOW_desc" type="String" name="TowDesc" length="250" />
<property column="bitcode" type="Int32" name="Bitcode" />
</class>
<query name="Two.GetAll">from Tow where Towid > 1 order by TOW_desc</query>
</hibernate-mapping>