Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Azure.Data.Tables] DeleteEntity overload #44986

Merged
merged 6 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ public TableClient(System.Uri endpoint, string tableName, Azure.Data.Tables.Tabl
public static string CreateQueryFilter<T>(System.Linq.Expressions.Expression<System.Func<T, bool>> filter) { throw null; }
public virtual Azure.Response Delete(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response> 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; }
JonathanCrd marked this conversation as resolved.
Show resolved Hide resolved
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<Azure.Response> 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<Azure.Response> 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; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
```
46 changes: 46 additions & 0 deletions sdk/tables/Azure.Data.Tables/src/TableClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,31 @@ public virtual async Task<Response> DeleteEntityAsync(
CancellationToken cancellationToken = default)
=> await DeleteEntityInternal(true, partitionKey, rowKey, ifMatch, cancellationToken).ConfigureAwait(false);

/// <summary>
/// Deletes the specified table entity.
/// </summary>
/// <remarks>Note: This method should not fail because the entity does not exist, however if delete operations are submitted in a <see cref="TableTransactionAction"/>, the transaction will fail if the entity does not exist.</remarks>
/// <param name="entity">The table entity to delete.</param>
/// <param name="ifMatch">
/// The If-Match value to be used for optimistic concurrency.
/// If <see cref="ETag.All"/> is specified, the operation will be executed unconditionally.
/// If the <see cref="ITableEntity.ETag"/> value is specified, the operation will fail with a status of 412 (Precondition Failed)
/// if the <see cref="ETag"/> value of the entity in the table does not match.
/// The default is to delete unconditionally.
/// </param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
/// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception>
/// <returns>The <see cref="Response"/> indicating the result of the operation.</returns>

public virtual async Task<Response> 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);
}

/// <summary>
/// Deletes the specified table entity.
/// </summary>
Expand All @@ -1316,6 +1341,27 @@ public virtual async Task<Response> DeleteEntityAsync(
public virtual Response DeleteEntity(string partitionKey, string rowKey, ETag ifMatch = default, CancellationToken cancellationToken = default)
=> DeleteEntityInternal(false, partitionKey, rowKey, ifMatch, cancellationToken).EnsureCompleted();

/// <summary>
/// Deletes the specified table entity.
/// </summary>
/// <remarks>Note: This method should not fail because the entity does not exist, however if delete operations are submitted in a <see cref="TableTransactionAction"/>, the transaction will fail if the entity does not exist.</remarks>
/// <param name="entity">The partitionKey that identifies the table entity.</param>
JonathanCrd marked this conversation as resolved.
Show resolved Hide resolved
/// <param name="ifMatch">
/// The If-Match value to be used for optimistic concurrency.
/// If <see cref="ETag.All"/> is specified, the operation will be executed unconditionally.
/// If the <see cref="ITableEntity.ETag"/> value is specified, the operation will fail with a status of 412 (Precondition Failed)
/// if the <see cref="ETag"/> value of the entity in the table does not match.
/// The default is to delete unconditionally.
/// </param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
/// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception>
/// <returns>The <see cref="Response"/> indicating the result of the operation.</returns>
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<Response> DeleteEntityInternal(
bool async,
string partitionKey,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Threading;

namespace Azure.Data.Tables
{
/// <summary>
Expand All @@ -21,7 +23,7 @@ public enum TableTransactionActionType
/// </summary>
UpdateReplace,
/// <summary>
/// Delete the entity. This is equivalent to <see cref="TableClient.DeleteEntity"/>
/// Delete the entity. This is equivalent to <see cref="TableClient.DeleteEntity(string, string, ETag, CancellationToken)"/>
/// </summary>
Delete,
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Loading