NHibernateは:基準Expression.InのHQL相当()?
-
22-08-2019 - |
質問
どのようにHQLで次の基準のクエリを表現するのでしょうか?
var idArray = new int[] { 1, 2, 3, 4, 5 };
Session.CreateCriteria(typeof(Foo))
.Add(Expression.In("Id", idArray)
.List<Foo>();
私はHQLのキーワード「に」があることを承知していますが、私はそれを理解するように、そのキーワードは「のようなサブクエリではなく、何か...で使用するためにここでIDが(1、2、3、4、 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>();
他のヒント
これはあまりにも動作します。
ICriteria sc = session.CreateCriteria(typeof(Foo));
sc.Add(Restrictions.In("id",new[] { 1, 2 }));
siteList = sc.List();
session.Close();
所属していません StackOverflow