How do I setup a Criteria in nHibernate to query against multiple values
- by AWC
I want to query for a set of results based on the contents of a list, I've managed to do this for a single instance of the class Foo, but I'm unsure how I would do this for a IList<Foo>.
So for a single instance of the class Foo, this works:
public ICriteria CreateCriteria(IList<Foo> foo)
{
return session
.CreateCriteria<Component>()
.CreateCriteria("Versions")
.CreateCriteria("PublishedEvents")
.Add(Restrictions.And(Restrictions.InsensitiveLike("Name", foo.Name, MatchMode.Anywhere),
Restrictions.InsensitiveLike("Type", foo.Type, MatchMode.Anywhere)))
.SetCacheable(true);
}
But how do I do this when the method parameter is a list of Foo?
public ICriteria CreateCriteria(IList<Foo> foos)
{
return session
.CreateCriteria<Component>()
.CreateCriteria("Versions")
.CreateCriteria("PublishedEvents")
.Add(Restrictions.And(Restrictions.InsensitiveLike("Name", foo.Name, MatchMode.Anywhere),
Restrictions.InsensitiveLike("Type", foo.Type, MatchMode.Anywhere)))
.SetCacheable(true);
}