Table of Contents

Struct ConditionStep

Namespace
DynaSharp
Assembly
DynaSharp.dll

A delete or a condition check in a transaction: what can follow it are its condition, the verbs of the next action, and sending. A check without a condition is rejected by DynamoDB. See TransactWriteExtensions for the rest.

public readonly ref struct ConditionStep : ITransactWriteStep<ConditionStep>, ITransactWriteChain<ConditionStep>, IConditional<ConditionStep>, IRetryable<ConditionStep>
Implements
Inherited Members
Extension Methods

Methods

If(ExpressionHandler)

Adds a condition in the grammar of DynamoDB, for what the conditions of handles do not cover. An interpolated Attr stands for an attribute name and any other interpolated value for a value. If it does not hold, the whole transaction is cancelled, and a second condition means both must hold.

public ConditionStep If(ExpressionHandler condition)

Parameters

condition ExpressionHandler

The condition.

Returns

ConditionStep

The step, which replaces this one.

IfVersion(long)

Makes this action depend on the item having this version. If it has another, the whole transaction is cancelled, and the marker of this action says that this was the reason.

public ConditionStep IfVersion(long version)

Parameters

version long

The version last read. A version of 0 stands for an item that does not exist, so it renders attribute_not_exists on the partition key. With Allow it stands for what reads as 0, an item without a version attribute or with 0 in it, or none.

Returns

ConditionStep

The step, which replaces this one.

Remarks

A key does not carry a version, so a delete of an entity with a VersionAttribute needs this or IgnoreVersion(), and the next action throws InvalidOperationException without it. A condition check needs neither, and this makes it a check on the version. RetryOnConflictAsync<TResult>(Func<CancellationToken, ValueTask<TResult>>, CancellationToken) repeats a transaction together with the read of the version.

Exceptions

ArgumentOutOfRangeException

version is negative, or MaxValue.

InvalidOperationException

The table of this action has no VersionAttribute.

If<TCondition>(TCondition)

Adds a condition. If it does not hold, the whole transaction is cancelled, and a second condition means both must hold.

public ConditionStep If<TCondition>(TCondition condition) where TCondition : ICondition

Parameters

condition TCondition

The condition.

Returns

ConditionStep

The step, which replaces this one.

Type Parameters

TCondition

The type of the condition.

Exceptions

ArgumentNullException

condition is null.

IgnoreVersion()

Lets this delete go out without the check.

public ConditionStep IgnoreVersion()

Returns

ConditionStep

The step, which replaces this one.

MaxAttempts(int)

Sets the number of attempts of this call including the first, in place of MaxAttempts. A retry after a lost response repeats a write that may have been applied, so 1 makes an ADD count at most once, and a lost response then reports a failure after the write was applied.

public ConditionStep MaxAttempts(int attempts)

Parameters

attempts int

The number of attempts.

Returns

ConditionStep

The command, which replaces this one.

Exceptions

ArgumentOutOfRangeException

attempts is below 1.

ToRequestJson()

Renders the body this transaction would send, as DynamoDB JSON, without sending it. It ends the command, and is meant for tests and debugging. The text contains the items and a generated token that nothing ever sends.

public string ToRequestJson()

Returns

string

The request body.

Exceptions

InvalidOperationException

The command was already sent, extended or rendered, or it has no action, which DynamoDB would reject.

Operators

implicit operator TransactWriteCommand(ConditionStep)

Hands the transaction on as a TransactWriteCommand, which is what a variable holds across a loop: tx = tx.Delete(table, key).IfExists();. This uses the step up like any call on it, so the command is the one handle left, and a clause of the action can no longer follow. What the action still owes, such as a version, is checked by the next verb.

public static implicit operator TransactWriteCommand(ConditionStep step)

Parameters

step ConditionStep

The step, which this replaces.

Returns

TransactWriteCommand

Exceptions

InvalidOperationException

The step was already sent, extended or rendered.