Parameterizing a HQL IN clause using HqlBasedQuery?

后端 未结 1 1252
抹茶落季
抹茶落季 2021-02-09 18:51

How do you pass a list of things for the \'in\' clause in Nhibernate HQL?

e.g.

// data input from the user interface, not known at compile time
object[]          


        
1条回答
  •  野的像风
    2021-02-09 19:20

    Use SetParameterList().

    Code snippet from billsternberger.net:

    ArrayList stateslist = new ArrayList();
    stateslist.Add("TX");
    stateslist.Add("VA");
    
    string hql = String.Format("FROM Contact c where State in (:states)");
    SimpleQuery q = new SimpleQuery(hql);
    q.SetParameterList("states", stateslist);
    
    Contact[] result = q.Execute();
    

    0 讨论(0)
提交回复
热议问题