我正在尝试从表A中删除多个记录,这些记录在表B中的id列表中退出,如下所示:
List<ulong> ids = new List<ulong> {1, 2};
string deleteQuery = string.Format(
@"DELETE FROM TABLE_A WHERE EXISTS
(SELECT id FROM TABLE_B WHERE checkpoint_id IN :idList)");
Session.CreateQuery(deleteQuery).SetParameterList("idList", ids).ExecuteUpdate();
我得到以下例外:
NHibernate.Hql.Ast.ANTLR.QuerySyntaxException: Exception of type 'Antlr.Runtime.NoViableAltException' was thrown. near line 2, column 100
如果我把列表硬编码[IN(1,2)]就行了。 我错过了什么?
答案 0 :(得分:2)
发现问题:
我需要在:idList周围添加额外的括号。
string deleteQuery = string.Format(
@"DELETE FROM TABLE_A WHERE EXISTS
(SELECT id FROM TABLE_B WHERE checkpoint_id IN (:idList))");