How do I setup a Criteria in nHibernate to query against multiple values

Posted by AWC on Stack Overflow See other posts from Stack Overflow or by AWC
Published on 2010-05-06T09:53:44Z Indexed on 2010/05/06 9:58 UTC
Read the original article Hit count: 294

Filed under:
|
|

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);
    }

© Stack Overflow or respective owner

Related posts about nhibernate

Related posts about criteria