diff --git a/sdk/tables/Azure.Data.Tables/CHANGELOG.md b/sdk/tables/Azure.Data.Tables/CHANGELOG.md index 60158b921fae7..8f987811ad61a 100644 --- a/sdk/tables/Azure.Data.Tables/CHANGELOG.md +++ b/sdk/tables/Azure.Data.Tables/CHANGELOG.md @@ -1,5 +1,16 @@ # Release History +## 12.8.4 + +### Features Added +- Overload the `DeleteEntity` method to allow an `ITableEntity` object as parameter. + +### Breaking Changes + +### Bugs Fixed + +### Other changes + ## 12.9.0-beta.1 (Unreleased) ### Features Added diff --git a/sdk/tables/Azure.Data.Tables/api/Azure.Data.Tables.netstandard2.0.cs b/sdk/tables/Azure.Data.Tables/api/Azure.Data.Tables.netstandard2.0.cs index 220d2f4d71c7f..556936064b8b3 100644 --- a/sdk/tables/Azure.Data.Tables/api/Azure.Data.Tables.netstandard2.0.cs +++ b/sdk/tables/Azure.Data.Tables/api/Azure.Data.Tables.netstandard2.0.cs @@ -30,7 +30,9 @@ public TableClient(System.Uri endpoint, string tableName, Azure.Data.Tables.Tabl public static string CreateQueryFilter(System.Linq.Expressions.Expression> filter) { throw null; } public virtual Azure.Response Delete(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task DeleteAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response DeleteEntity(Azure.Data.Tables.ITableEntity entity, Azure.ETag ifMatch = default(Azure.ETag), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response DeleteEntity(string partitionKey, string rowKey, Azure.ETag ifMatch = default(Azure.ETag), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task DeleteEntityAsync(Azure.Data.Tables.ITableEntity entity, Azure.ETag ifMatch = default(Azure.ETag), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task DeleteEntityAsync(string partitionKey, string rowKey, Azure.ETag ifMatch = default(Azure.ETag), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Uri GenerateSasUri(Azure.Data.Tables.Sas.TableSasBuilder builder) { throw null; } public virtual System.Uri GenerateSasUri(Azure.Data.Tables.Sas.TableSasPermissions permissions, System.DateTimeOffset expiresOn) { throw null; } diff --git a/sdk/tables/Azure.Data.Tables/samples/Sample2CreateDeleteEntities.md b/sdk/tables/Azure.Data.Tables/samples/Sample2CreateDeleteEntities.md index 4725ba7191c93..ef81b37f0dda2 100644 --- a/sdk/tables/Azure.Data.Tables/samples/Sample2CreateDeleteEntities.md +++ b/sdk/tables/Azure.Data.Tables/samples/Sample2CreateDeleteEntities.md @@ -95,3 +95,10 @@ To delete an entity, invoke `DeleteEntity` and pass in its partition and row key // Delete the entity given the partition and row key. tableClient.DeleteEntity(partitionKey, rowKey); ``` + +Alternatively, you can pass a `TableEntity`object. + +```C# Snippet:TablesSample2DeleteEntityUsingObject +// Delete an entity given a TableEntity object +tableClient.DeleteEntity(tableEntity); +``` diff --git a/sdk/tables/Azure.Data.Tables/src/TableClient.cs b/sdk/tables/Azure.Data.Tables/src/TableClient.cs index b1cd3bce1f1a4..e419daaa295b6 100644 --- a/sdk/tables/Azure.Data.Tables/src/TableClient.cs +++ b/sdk/tables/Azure.Data.Tables/src/TableClient.cs @@ -1297,6 +1297,31 @@ public virtual async Task DeleteEntityAsync( CancellationToken cancellationToken = default) => await DeleteEntityInternal(true, partitionKey, rowKey, ifMatch, cancellationToken).ConfigureAwait(false); + /// + /// Deletes the specified table entity. + /// + /// Note: This method should not fail because the entity does not exist, however if delete operations are submitted in a , the transaction will fail if the entity does not exist. + /// The table entity to delete. + /// + /// The If-Match value to be used for optimistic concurrency. + /// If is specified, the operation will be executed unconditionally. + /// If the value is specified, the operation will fail with a status of 412 (Precondition Failed) + /// if the value of the entity in the table does not match. + /// The default is to delete unconditionally. + /// + /// A controlling the request lifetime. + /// The server returned an error. See for details returned from the server. + /// The indicating the result of the operation. + + public virtual async Task DeleteEntityAsync( + ITableEntity entity, + ETag ifMatch = default, + CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(entity, nameof(entity)); + return await DeleteEntityInternal(true, entity.PartitionKey, entity.RowKey, ifMatch, cancellationToken).ConfigureAwait(false); + } + /// /// Deletes the specified table entity. /// @@ -1316,6 +1341,27 @@ public virtual async Task DeleteEntityAsync( public virtual Response DeleteEntity(string partitionKey, string rowKey, ETag ifMatch = default, CancellationToken cancellationToken = default) => DeleteEntityInternal(false, partitionKey, rowKey, ifMatch, cancellationToken).EnsureCompleted(); + /// + /// Deletes the specified table entity. + /// + /// Note: This method should not fail because the entity does not exist, however if delete operations are submitted in a , the transaction will fail if the entity does not exist. + /// The table entity to delete. + /// + /// The If-Match value to be used for optimistic concurrency. + /// If is specified, the operation will be executed unconditionally. + /// If the value is specified, the operation will fail with a status of 412 (Precondition Failed) + /// if the value of the entity in the table does not match. + /// The default is to delete unconditionally. + /// + /// A controlling the request lifetime. + /// The server returned an error. See for details returned from the server. + /// The indicating the result of the operation. + public virtual Response DeleteEntity(ITableEntity entity, ETag ifMatch = default, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(entity, nameof(entity)); + return DeleteEntityInternal(false, entity.PartitionKey, entity.RowKey, ifMatch, cancellationToken).EnsureCompleted(); + } + internal async Task DeleteEntityInternal( bool async, string partitionKey, diff --git a/sdk/tables/Azure.Data.Tables/src/TableTransactionActionType.cs b/sdk/tables/Azure.Data.Tables/src/TableTransactionActionType.cs index 743381e1bff1f..d3bdb38fd22da 100644 --- a/sdk/tables/Azure.Data.Tables/src/TableTransactionActionType.cs +++ b/sdk/tables/Azure.Data.Tables/src/TableTransactionActionType.cs @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +using System.Threading; + namespace Azure.Data.Tables { /// @@ -21,7 +23,7 @@ public enum TableTransactionActionType /// UpdateReplace, /// - /// Delete the entity. This is equivalent to + /// Delete the entity. This is equivalent to /// Delete, /// diff --git a/sdk/tables/Azure.Data.Tables/tests/samples/Sample2_CreateDeleteEntities.cs b/sdk/tables/Azure.Data.Tables/tests/samples/Sample2_CreateDeleteEntities.cs index 24467f0fa2cc7..4034f9af72da9 100644 --- a/sdk/tables/Azure.Data.Tables/tests/samples/Sample2_CreateDeleteEntities.cs +++ b/sdk/tables/Azure.Data.Tables/tests/samples/Sample2_CreateDeleteEntities.cs @@ -5,13 +5,15 @@ using Azure.Core.TestFramework; using NUnit.Framework; using Azure.Data.Tables.Tests; +using System.Xml; namespace Azure.Data.Tables.Samples { public partial class TablesSamples : TablesTestEnvironment { - [Test] - public void CreateDeleteEntity() + [TestCase(true)] + [TestCase(false)] + public void CreateDeleteEntity(bool useEntity) { string storageUri = StorageUri; string accountName = StorageAccountName; @@ -95,10 +97,20 @@ public void CreateDeleteEntity() Console.WriteLine($"{marker.PartitionKey}, {marker.RowKey}, {marker.Product}, {marker.Price}, {marker.Quantity}"); #endregion - #region Snippet:TablesSample2DeleteEntity - // Delete the entity given the partition and row key. - tableClient.DeleteEntity(partitionKey, rowKey); - #endregion + if (useEntity) + { + #region Snippet:TablesSample2DeleteEntity + // Delete the entity given the partition and row key. + tableClient.DeleteEntity(partitionKey, rowKey); + #endregion + } + else + { + #region Snippet:TablesSample2DeleteEntityUsingObject + // Delete an entity given a TableEntity object + tableClient.DeleteEntity(tableEntity); + #endregion + } tableClient.Delete(); } diff --git a/sdk/tables/Azure.Data.Tables/tests/samples/Sample2_CreateDeleteEntitiesAsync.cs b/sdk/tables/Azure.Data.Tables/tests/samples/Sample2_CreateDeleteEntitiesAsync.cs index f074a7ff9d878..c2d7365fefc18 100644 --- a/sdk/tables/Azure.Data.Tables/tests/samples/Sample2_CreateDeleteEntitiesAsync.cs +++ b/sdk/tables/Azure.Data.Tables/tests/samples/Sample2_CreateDeleteEntitiesAsync.cs @@ -61,6 +61,9 @@ public async Task CreateDeleteEntitiesAsync() // Delete the entity given the partition and row key. await client.DeleteEntityAsync(partitionKey, rowKey); + + // Delete the strong entity given the entity object. + await client.DeleteEntityAsync(strongEntity); await client.DeleteAsync(); }