/// <summary>
        /// Deletes an entities from the table with the specified partitionKey
        /// </summary>
        /// <param name="partitionKey">
        /// The partition key of the entity to be deleted.
        /// Note that a partition key can return more than one entity.
        /// If more than one are returned, the first one is deleted.
        /// </param>
        public async Task DeleteEntitiesByPartitionKeyAsync(string partitionKey)
        {
            Validate.TablePropertyValue(partitionKey, "partitionKey");

            var query =
                new TableQuery <T>()
                .Where(TableQuery.GenerateFilterCondition(
                           "PartitionKey",
                           QueryComparisons.Equal,
                           partitionKey));

            var results = await cloudTable.ExecuteQueryAsync(query);

            var batchOperation = new TableBatchOperation();
            var counter        = 0;

            foreach (var entity in results)
            {
                batchOperation.Delete(entity);
                counter++;

                //Batch operations are limited to 100 items
                //when we reach 100, we commit and clear the operation
                if (counter == 100)
                {
                    await cloudTable.ExecuteBatchAsync(batchOperation);

                    batchOperation = new TableBatchOperation();
                    counter        = 0;
                }
            }
        }
Example #2
0
        /// <summary>
        /// Deletes an entities from the table with the specified partitionKey
        /// </summary>
        /// <param name="rowKey">
        /// The row key of the entities to be deleted.
        /// Note that a row key can return more than one entity.
        /// If more than one are returned, the first one is deleted.
        /// </param>
        public void DeleteEntitiesByRowKey(string rowKey)
        {
            Validate.TablePropertyValue(rowKey, "rowKey");

            var query =
                new TableQuery <T>()
                .Where(TableQuery.GenerateFilterCondition(
                           "RowKey",
                           QueryComparisons.Equal,
                           rowKey));

            var results        = cloudTable.ExecuteQuery(query);
            var batchOperation = new TableBatchOperation();
            var counter        = 0;

            foreach (var entity in results)
            {
                batchOperation.Delete(entity);
                counter++;

                //Batch operations are limited to 100 items
                //when we reach 100, we commit and clear the operation
                if (counter == 100)
                {
                    cloudTable.ExecuteBatch(batchOperation);
                    batchOperation = new TableBatchOperation();
                    counter        = 0;
                }
            }
        }
        /// <summary>
        /// Gets all entities from the table with the specified rowKey
        /// </summary>
        /// <param name="rowKey">
        /// The row key of the entities to be returned.
        /// </param>
        public async Task <IEnumerable <T> > GetEntitiesByRowKeyAsync(string rowKey)
        {
            Validate.TablePropertyValue(rowKey, "rowKey");

            var query =
                new TableQuery <T>()
                .Where(TableQuery.GenerateFilterCondition(
                           "RowKey",
                           QueryComparisons.Equal,
                           rowKey));

            return(await cloudTable.ExecuteQueryAsync(query));
        }
Example #4
0
        /// <summary>
        /// Gets all entities from the table with the property
        /// </summary>
        /// <param name="property">
        /// The search column name for value search.
        /// </param>
        /// <param name="value">
        /// The search value to match for returned entities.
        /// </param>
        public async Task <IEnumerable <T> > GetEntitiesByPropertyAsync(string property, string value)
        {
            Validate.TablePropertyValue(value, property);

            var query =
                new TableQuery <T>()
                .Where(TableQuery.GenerateFilterCondition(
                           property,
                           QueryComparisons.Equal,
                           value));

            return(await ExecuteQueryAsync(query));
        }
Example #5
0
        /// <summary>
        /// Gets an entity from the table
        /// </summary>
        /// <param name="partitionKey">
        /// The partition key of the entity to be returned.
        /// </param>
        public IEnumerable <T> GetEntitiesByPartitionKey(string partitionKey)
        {
            Validate.TablePropertyValue(partitionKey, "partitionKey");

            var query =
                new TableQuery <T>()
                .Where(TableQuery.GenerateFilterCondition(
                           "PartitionKey",
                           QueryComparisons.Equal,
                           partitionKey));

            return(cloudTable.ExecuteQuery(query).AsEnumerable());
        }
        /// <summary>
        /// Deletes an entity from the table
        /// </summary>
        /// <param name="partitionKey">The partitionKey of the entity</param>
        /// <param name="rowKey">The row key of the entity to be deleted</param>
        public async Task DeleteEntityAsync(string partitionKey, string rowKey)
        {
            Validate.TablePropertyValue(rowKey, "rowKey");
            Validate.TablePropertyValue(partitionKey, "partitionKey");

            var retrieveOperation = TableOperation.Retrieve <T>(partitionKey, rowKey);
            var retrievedResult   = await cloudTable.ExecuteAsync(retrieveOperation);

            var entityToDelete = retrievedResult.Result as T;

            if (entityToDelete != null)
            {
                var deleteOperation = TableOperation.Delete(entityToDelete);
                await cloudTable.ExecuteAsync(deleteOperation);
            }
        }