开发者

Whats wrong with my Nhibernate HQL query?

开发者 https://www.devze.com 2023-02-27 02:35 出处:网络
I have this public List<TableA> GetRecords(List<string> keys) { const string query = \"FROM TableA WHERE `Key` = :keys\";

I have this

public List<TableA> GetRecords(List<string> keys)
    {
        const string query = "FROM TableA WHERE `Key` = :keys";
        return session.CreateQuery(query).SetParameterList("keys",keys).List<TableA>().ToList();
    }

I get it could not execute error "could not execute query"

when I look at it my where clause is always equal to "?" . So it's like not using my list to fill it in.

Edit

If I have this

List<strings> myKeys = new List<strings> {"1", "2"};
GetRecords(myKeys)

It will fail

If I have

List<strings> myKeys = new List<strings> {"1"};
GetRecords(myKeys)

It works. So it can't handle for some reason more th开发者_如何学Goan one value.


You should have "in" instead of "="

const string query = "FROM TableA WHERE Key in (:keys)";
0

精彩评论

暂无评论...
验证码 换一张
取 消