views:

1070

answers:

1

How would you express the following Criteria query in HQL?

var idArray = new int[] { 1, 2, 3, 4, 5 };

Session.CreateCriteria(typeof(Foo))
    .Add(Expression.In("Id", idArray)
    .List<Foo>();

I am aware of that there is an "in" keyword in HQL, but as I understand it that keyword is for use with subqueries rather than something like "... where Id in (1, 2, 3, 4, 5)" or such. If that is not the case, I will gladly accept corrections.

Thanks /Erik

+4  A: 

Try this:

var idArray = new int[] { 1, 2, 3, 4, 5 };
var foos = Session
    .CreateQuery("from Foo f where f.Id in (:ids)")
    .SetParameterList("ids", idArray)
    .List<Foo>();
Darin Dimitrov
Worked great, thanks!
Erik Öjebo