Parameterizing a HQL IN clause using HqlBasedQuery?

后端 未结 1 1251
抹茶落季
抹茶落季 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<Contact> q = new SimpleQuery<Contact>(hql);
    q.SetParameterList("states", stateslist);
    
    Contact[] result = q.Execute();
    
    0 讨论(0)
提交回复
热议问题