Table of Contents

Class Change<T>

Namespace
DynaSharp.Streams
Assembly
DynaSharp.dll

A change of an item of one entity, read from the images of a stream record: what As<T>() and ReadChangesAsync of TableStreamExtensions give.

public sealed record Change<T> : IEquatable<Change<T>> where T : IDynamoDbEntity<T>

Type Parameters

T

The entity.

Inheritance
Change<T>
Implements
Inherited Members

Examples

await foreach (Change<Order> change in orders.ReadChangesAsync(streams, ShardIteratorType.Latest, cancellationToken: ct))
{
    if (change.Kind == OperationType.Insert)
    {
        Console.WriteLine(change.After!.Number);
    }
}

Remarks

A stream cannot be filtered at its source, so a table that holds several entities streams all of them, and the type is decided here, from the images: an image is a T when its discriminator attribute holds the discriminator of the entity, as Is<T>() tests. For an entity without a discriminator, [Discriminator(OptOut = true)], nothing tells its items from others, so every image is one.

Kind is what happened to the T, which is not always the kind of the record: an item whose discriminator changes at one key, an ORDER that becomes an INVOICE in one MODIFY, is an order removed and an invoice inserted, so the change of the order has Remove and that of the invoice Insert, both with the sequence number of the record. A typed read gives the removal first.

What can be typed depends on the view of the stream. NewAndOldImages types every change. NewImage has no old image, so Before is never set and a removal has no image to be typed by. OldImage has no new image, so After is never set and an insert is not typed. A MODIFY with only one image stays Modify with the other side empty, and cannot show a change of the type. KeysOnly has no image, so nothing is typed.

Constructors

Change()

public Change()

Properties

After

Gets the item after the change, read from the new image, or null when there is no new image of a T; for an entity that is a struct, its default value then, and Kind tells.

public T? After { get; init; }

Property Value

T

Before

Gets the item before the change, read from the old image, or null when there is no old image of a T; for an entity that is a struct, its default value then, and Kind tells.

public T? Before { get; init; }

Property Value

T

Keys

Gets the key attributes of the item, as stored, Keys of the record. DynamoDB sends them with every record: null only if the response omits them.

public IReadOnlyDictionary<string, AttributeValue>? Keys { get; init; }

Property Value

IReadOnlyDictionary<string, AttributeValue>

Kind

Gets what happened to the T: Insert with After alone, Remove with Before alone, and Modify with both, or with the one image the view of the stream has. Never Unknown.

public OperationType Kind { get; init; }

Property Value

OperationType

Record

Gets the record the change was read from, with what the change does not repeat: ApproximateCreationDateTime, and UserIdentity, which tells a deletion by time to live.

public required ChangeRecord Record { get; init; }

Property Value

ChangeRecord

SequenceNumber

Gets the sequence number of the record, SequenceNumber. Both changes of an item whose type changed have the one of their record. DynamoDB sends it with every record: null only if the response omits it.

public string? SequenceNumber { get; init; }

Property Value

string

Methods

Equals(Change<T>?)

public bool Equals(Change<T>? other)

Parameters

other Change<T>

Returns

bool

Equals(object?)

public override bool Equals(object? obj)

Parameters

obj object

Returns

bool

GetHashCode()

public override int GetHashCode()

Returns

int

ToString()

public override string ToString()

Returns

string

Operators

operator ==(Change<T>?, Change<T>?)

public static bool operator ==(Change<T>? left, Change<T>? right)

Parameters

left Change<T>
right Change<T>

Returns

bool

operator !=(Change<T>?, Change<T>?)

public static bool operator !=(Change<T>? left, Change<T>? right)

Parameters

left Change<T>
right Change<T>

Returns

bool