Reputation: 1352
I have several ICriterion instances that I combine in various ways (conjunction, disjunction, etc.) based on user input. I'm having trouble creating an ICriterion that is based on matching a value in an associated collection.
For example, given a one-to-many relationship between Orders and OrderItems, I want to be able to create an ICriterion that selects all Orders that have an OrderItem with a Quantity > 100.
I've tried several things and haven't yet found anything that works.
Upvotes: 1
Views: 1826
Reputation: 30813
i had a the same problem in a project. you need a pair of alias and criteria for each filtered collection.
KeyValuePair<string, ICriterion[]> collectionfilters = GetFromSomeWhere();
foreach (var association in collectionfilters)
{
criteria.CreateAlias(association.Key, association.Key);
foreach(var crit in association.Value)
{
criteria.Add(crit);
}
}
// example
KeyValuePair<string, ICriterion[]> GetFromSomeWhere()
{
return new KeyValuePair<string, ICriterion[]>("OrderItems", new []{ Restrictions.Gt("OrderItems.Quantity", 100) });
}
Upvotes: 1