2012-09-24 43 views
1

我試圖刪除離開在表B ID列表表A的多條記錄如下刪除多條記錄:NHibernate的由ID的列表與的createQuery

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)]起作用。 我錯過了什麼?

回答

2

發現了問題:

我需要一個額外的括號約於:IDLIST。

string deleteQuery = string.Format(
      @"DELETE FROM TABLE_A WHERE EXISTS 
      (SELECT id FROM TABLE_B WHERE checkpoint_id IN (:idList))");