I have two tables; Person and Licenses. A Person can have many licenses. The Person mapping has a bag for Licenses and the Person class has an IList for Licenses. I want to retrieve only Person's that have Issued Licenses. This I can get to work just fine. I also only want the issued Licenses in the Person Licence list. I have tried various things but any Person objects I get back have all the Licenses for that Person in the License list not just the Issued ones.
BAG mapping for PersonCode:
<class name="Person" table="_Person" >
<bag name="Licenses" lazy="false" inverse="true" fetch="join" cascade="all">
<key column="Licensee" />
<one-to-many class="License" />
</bag>
I also have a many to one in the licence class:
Code:
<many-to-one name="Licensee" class="Person" lazy="false" not-null="true" fetch="join" cascade="none" />
Criteria query to get Person objects with only Issued LicensesCode:
ICriteria crit = session.CreateCriteria(typeof(Person));
ICriteria licenceCrit = crit.CreateCriteria("Licenses", JoinType.InnerJoin);
licenceCrit.Add(Restrictions.Eq("Status", LicenseStatus.Issued));
crit.SetResultTransformer(new DistinctRootEntityResultTransformer());
var result = crit.List<Person>();
As mentioned this works fine, I only get Person objects with Issued Licenses but how can I get the Person objects to only have the Issued Licenses in their Licenses collection?
Thanks!