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

Merge always updates for batch operations #18446

Merged
merged 1 commit into from
Feb 5, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
24 changes: 10 additions & 14 deletions sdk/tables/Azure.Data.Tables/src/TableTransactionalBatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,7 @@ internal virtual void SetBatchGuids(Guid batchGuid, Guid changesetGuid)
/// <param name="mode">Determines the behavior of the Update operation.</param>
public virtual void UpdateEntity<T>(T entity, ETag ifMatch, TableUpdateMode mode = TableUpdateMode.Merge) where T : class, ITableEntity, new()
{
var message = _batchOperations.CreateUpdateEntityRequest(
_table,
entity.PartitionKey,
entity.RowKey,
null,
ifMatch: ifMatch.ToString(),
tableEntityProperties: entity.ToOdataAnnotatedDictionary(),
queryOptions: new QueryOptions() { Format = _format });

HttpMessage message = CreateUpdateOrMergeRequest<T>(entity, mode, ifMatch);
AddMessage(entity, message, RequestType.Update);
}

Expand All @@ -141,28 +133,32 @@ internal virtual void SetBatchGuids(Guid batchGuid, Guid changesetGuid)
/// <param name="mode">Determines the behavior of the update operation when the entity already exists in the table. See <see cref="TableUpdateMode"/> for more details.</param>
public virtual void UpsertEntity<T>(T entity, TableUpdateMode mode = TableUpdateMode.Merge) where T : class, ITableEntity, new()
{
var message = mode switch
HttpMessage message = CreateUpdateOrMergeRequest<T>(entity, mode, default);
AddMessage(entity, message, RequestType.Upsert);
}

private HttpMessage CreateUpdateOrMergeRequest<T>(T entity, TableUpdateMode mode, ETag ifMatch = default) where T : class, ITableEntity, new()
{
return mode switch
{
TableUpdateMode.Replace => _batchOperations.CreateUpdateEntityRequest(
_table,
entity.PartitionKey,
entity.RowKey,
null,
ifMatch: null,
ifMatch: ifMatch == default ? null : ifMatch.ToString(),
tableEntityProperties: entity.ToOdataAnnotatedDictionary(),
queryOptions: new QueryOptions() { Format = _format }),
TableUpdateMode.Merge => _batchOperations.CreateMergeEntityRequest(
_table,
entity.PartitionKey,
entity.RowKey,
null,
ifMatch: null,
ifMatch: ifMatch == default ? null : ifMatch.ToString(),
entity.ToOdataAnnotatedDictionary(),
new QueryOptions() { Format = _format }),
_ => throw new ArgumentException($"Unexpected value for {nameof(mode)}: {mode}")
};

AddMessage(entity, message, RequestType.Upsert);
}

/// <summary>
Expand Down
Loading