1

您将如何在 HQL 中表达以下 Criteria 查询?

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

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

我知道 HQL 中有一个“in”关键字,但据我了解,该关键字用于子查询,而不是像“... where Id in (1, 2, 3, 4, 5)”之类的东西之类的。如果不是这样,我很乐意接受更正。

谢谢/埃里克

4

2 回答 2

5

试试这个:

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>();
于 2009-03-26T19:00:08.097 回答
1

这也有效

ICriteria sc = session.CreateCriteria(typeof(Foo));
sc.Add(Restrictions.In("id",new[] { 1, 2 }));
siteList = sc.List();
session.Close();
于 2011-02-09T20:12:35.753 回答