public WhereNotInSubquery ( string query, string table, string column, string subQuery ) : string | ||
query | string | The query. |
table | string | The table the column belongs to. |
column | string | The column. |
subQuery | string | The subQuery. |
return | string |
/// <summary> /// Deletes all data associated to a document. /// </summary> /// <param name="document">The document.</param> /// <param name="state">A state object passed from the index (can be <c>null</c> or a <see cref="T:DbTransaction" />).</param> private void DeleteDataForDocument(IDocument document, object state) { // 1. Delete all data related to a document // 2. Delete all words that have no more mappings ICommandBuilder builder = GetCommandBuilder(); QueryBuilder queryBuilder = new QueryBuilder(builder); string query = queryBuilder.DeleteFrom("IndexDocument"); query = queryBuilder.Where(query, "Name", WhereOperator.Equals, "DocName"); List<Parameter> parameters = new List<Parameter>(1); parameters.Add(new Parameter(ParameterType.String, "DocName", document.Name)); string subQuery = queryBuilder.SelectFrom("IndexWordMapping", new string[] { "Word" }); subQuery = queryBuilder.GroupBy(subQuery, new string[] { "Word" }); string query2 = queryBuilder.DeleteFrom("IndexWord"); query2 = queryBuilder.WhereNotInSubquery(query2, "IndexWord", "Id", subQuery); query = queryBuilder.AppendForBatch(query, query2); DbCommand command = null; if(state != null) command = builder.GetCommand((DbTransaction)state, query, parameters); else command = builder.GetCommand(connString, query, parameters); // Close only if state is null ExecuteNonQuery(command, state == null); }