Esempio n. 1
0
        private static void DeleteByIndex(JsonOperationContext context, string indexName, DocumentStore store)
        {
            var deleteByIndexOperation = new DeleteByIndexOperation();
            var command = deleteByIndexOperation.CreateRequest(indexName, new IndexQuery(),
                                                               new QueryOperationOptions {
                AllowStale = false
            }, store);

            if (command != null)
            {
                store.GetRequestExecuter(store.DefaultDatabase).Execute(command, context);
            }
        }
Esempio n. 2
0
        public async void Delete_By_Index_Async()
        {
            using (var store = GetDocumentStore())
            {
                using (var session = store.OpenAsyncSession())
                {
                    await session.StoreAsync(new User { Name = "Fitzchak" }, "users/1");

                    await session.StoreAsync(new User { Name = "Arek" }, "users/2");

                    await session.SaveChangesAsync();
                }

                string indexName;
                using (var session = store.OpenSession())
                {
                    RavenQueryStatistics stats;
                    var people = session.Query <User>()
                                 .Customize(x => x.WaitForNonStaleResults())
                                 .Statistics(out stats)
                                 .Where(x => x.Name == "Arek")
                                 .ToList();

                    indexName = stats.IndexName;
                }

                JsonOperationContext context;
                store.GetRequestExecuter(store.DefaultDatabase).ContextPool.AllocateOperationContext(out context);


                var deleteByIndexOperation = new DeleteByIndexOperation();
                var command = deleteByIndexOperation.CreateRequest(indexName, new IndexQuery(),
                                                                   new QueryOperationOptions {
                    AllowStale = false
                }, store);

                if (command != null)
                {
                    await store.GetRequestExecuter(store.DefaultDatabase).ExecuteAsync(command, context);
                }
                var databaseStatistics = DatabaseStatistics(store, context);

                //TODO - after we have hilo need to be 1
                Assert.Equal(0, databaseStatistics.CountOfDocuments);
            }
        }
Esempio n. 3
0
        public Operation DeleteByIndex <T>(string indexName, Expression <Func <T, bool> > expression)
        {
            var query      = Query <T>(indexName).Where(expression);
            var indexQuery = new IndexQuery()
            {
                Query = query.ToString()
            };

            var deleteByIndexOperation = new DeleteByIndexOperation();
            var command = deleteByIndexOperation.CreateRequest(indexName, indexQuery,
                                                               new QueryOperationOptions(), (DocumentStore)this.DocumentStore);

            if (command != null)
            {
                RequestExecuter.Execute(command, Context);
                return(new Operation(command.Result.OperationId));
            }
            return(null);
        }