Reputation:
Just a quick question. If I've got 2 tables that are joined in a 3rd table with a many-to-many relationship, is it possible to write an ICriteria with expressions in one of the tables and the join table?
Lets say the mapping file looks something like:
<bag name ="Bag" table="JoinTable" cascade ="none">
<key column="Data_ID"/>
<many-to-many class="Data2" column="Data2_ID"/>
</bag>
Is it then possible to write an ICriteria like the following?
ICriteria crit = session.CreateCriteria(typeof(Data));
crit.Add(Expression.Eq("Name", name));
crit.Add(Expression.Between("Date", startDate, endDate));
crit.Add(Expression.Eq("Bag", data2IDNumber));
When I try this, it tells me I the expected type is IList, whereas the actual type is Bag.
Thanks.
Upvotes: 0
Views: 1454
Reputation: 56944
You should do it like this (i think)
ICriteria crit = session.CreateCriteria (typeof(Data));
crit.Add (Expression.Eq ("Name", name));
crit.Add (Expression.Between ("Date", startDate, endDate));
crit.CreateAlias ("Bag", "b");
crit.Add (Expression.Eq ("b.Id", data2IDNumber));
Upvotes: 1