public void Delete(IEnumerable <long> ids, bool inTransaction = true) { TransactionState txn = null; if (inTransaction) { txn = Database.StartTransaction(); } try { var pages = ids.SplitIntoPages(500); foreach (var page in pages) { var sql = new SqlStatement(); var builder = new StringBuilder(); builder.Append("delete from "); builder.Append(sql.Dialect.FormatTableName(this.EntityType.NativeName)); builder.Append(" where "); builder.Append(sql.Dialect.FormatColumnName(this.EntityType.GetKeyFields()[0].NativeName)); builder.Append(" in ("); sql.AddValueList <long>(builder, page); builder.Append(")"); sql.CommandText = builder.ToString(); Database.ExecuteNonQuery(sql); } // ok... if (txn != null) { txn.Commit(); } } catch (Exception ex) { if (txn != null) { txn.Rollback(ex); } throw new InvalidOperationException("The operation failed", ex); } finally { if (txn != null) { txn.Dispose(); } } }