Table of Contents

Class EntityTableExtensions

Namespace
DynaSharp
Assembly
DynaSharp.dll

The verbs of a table or index of an entity that take what the entity builds: a partition key of Keys for a query, the entity itself for a get or a delete, and an index by the name the entity declares. These are extension methods because they depend on the type of the table: a table without a schema takes such a key too, for a mixed read.

public static class EntityTableExtensions
Inheritance
EntityTableExtensions
Inherited Members

Examples

await foreach (var order in orders.Query(Order.Keys.Pk.Of("alice")).ItemsAsync(ct))
{
    Console.WriteLine(order.Total);
}

Methods

Delete<T>(Table<T>, T)

Starts a DeleteItem of the item under the key of an entity. An entity with a VersionAttribute gives its version as well, so the delete happens only if the item still has that version.

public static DeleteCommand<T> Delete<T>(this Table<T> table, T entity) where T : IDynamoDbEntity<T>

Parameters

table Table<T>

The table.

entity T

The entity to take the key and the version from.

Returns

DeleteCommand<T>

The command.

Type Parameters

T

The entity.

Remarks

The version check is that of IfVersion<T>(DeleteCommand<T>, long): if the item has another version, sending throws ConditionalCheckFailedException. IgnoreVersion<T>(DeleteCommand<T>) gives the check up, and IfVersion<T>(DeleteCommand<T>, long) checks another version in its place. The other attributes of the entity play no part, and an entity without a version gives only its key.

Version 0 stands for an item that does not exist, so it renders attribute_not_exists on the partition key: an entity at 0 deletes nothing, and fails on any item under its key, also on one without a version attribute, which IgnoreVersion<T>(DeleteCommand<T>) deletes, and which Allow deletes at 0, by looking at the version attribute instead, as it deletes one that holds 0.

Exceptions

ArgumentNullException

entity is null.

OverflowException

The version of the entity does not fit a long.

Get<T>(Table<T>, T)

Starts a get of the item under the key of an entity, which is how a reload reads.

public static GetCommand<T> Get<T>(this Table<T> table, T entity) where T : IDynamoDbEntity<T>

Parameters

table Table<T>

The table.

entity T

The entity to take the key from.

Returns

GetCommand<T>

The command.

Type Parameters

T

The entity.

Exceptions

ArgumentNullException

entity is null.

Index<TEntity>(Table<Item>, string)

Gets a secondary index of a table without a schema, with the key names an entity declares: shop.Index<Membership>(Membership.Indexes.Gsi1). A mixed read goes through this table, so this is how it reads an index without naming its keys again. Items are read as Item until Of<...>() says otherwise, and the entity says nothing else. Hold it in a field.

public static Index<Item> Index<TEntity>(this Table<Item> table, string name) where TEntity : IDynamoDbEntity<TEntity>

Parameters

table Table<Item>

The table.

name string

The name of the index.

Returns

Index<Item>

The index.

Type Parameters

TEntity

The entity that declares the index.

Exceptions

ArgumentException

The entity does not declare an index of this name.

Index<T>(Table<T>, string)

Gets a secondary index that the entity declares, with its key names: orders.Index(Order.Indexes.ByStatus). An index is read through its own type, which has no writes. Hold it in a field.

public static Index<T> Index<T>(this Table<T> table, string name) where T : IDynamoDbEntity<T>

Parameters

table Table<T>

The table.

name string

The name of the index.

Returns

Index<T>

The index.

Type Parameters

T

The entity.

Exceptions

ArgumentException

The entity does not declare an index of this name.

QueryByDiscriminator<T>(Index<T>, SortKeyCondition)

Starts a query of an index keyed by the discriminator of the entity, whose partition holds every item of it: orders.Index("ByType", "_type", "sk").QueryByDiscriminator(). No generated builder makes that key, because the discriminator is no property.

public static QueryCommand<T> QueryByDiscriminator<T>(this Index<T> index, SortKeyCondition sortKey = default) where T : IDynamoDbEntity<T>

Parameters

index Index<T>

The index.

sortKey SortKeyCondition

The condition on the sort key of the index, or the default value to read the whole partition.

Returns

QueryCommand<T>

The command.

Type Parameters

T

The entity.

Remarks

Keyed by the discriminator. The partition key of the index has to be the attribute of the discriminator, else this throws ArgumentException, as a key of another attribute does. DynamoDB refuses a filter on a key, so the key condition decides which items are read, see Index<T>.

Exceptions

ArgumentNullException

index is null.

InvalidOperationException

T has no discriminator.

ArgumentException

The partition key of the index is another attribute, or there is a condition on a sort key and the index has none.

Query<TEntity>(Index<Item>, PartitionKey<TEntity>, SortKeyCondition)

Starts a query of one partition of an index without a schema, by the key of any entity, for a mixed read. See Index<T> for what is different about reading an index.

public static QueryCommand<Item> Query<TEntity>(this Index<Item> index, PartitionKey<TEntity> partitionKey, SortKeyCondition sortKey = default) where TEntity : IDynamoDbEntity<TEntity>

Parameters

index Index<Item>

The index.

partitionKey PartitionKey<TEntity>

The partition key of the index.

sortKey SortKeyCondition

The condition on the sort key of the index, or the default value to read the whole partition.

Returns

QueryCommand<Item>

The command.

Type Parameters

TEntity

The entity the key belongs to.

Exceptions

ArgumentException

The key is the default value, it was built for another attribute, or there is a condition on a sort key and the index has none.

Query<TEntity>(Index<Item>, IEnumerable<PartitionKey<TEntity>>, SortKeyCondition)

Starts a query of several partitions of an index without a schema, by the keys of any entity. It costs at least one read per partition, see FanOutQueryCommand<T>.

public static FanOutQueryCommand<Item> Query<TEntity>(this Index<Item> index, IEnumerable<PartitionKey<TEntity>> partitionKeys, SortKeyCondition sortKey = default) where TEntity : IDynamoDbEntity<TEntity>

Parameters

index Index<Item>

The index.

partitionKeys IEnumerable<PartitionKey<TEntity>>

The partitions, enumerated once, here. Their order breaks ties between equal sort keys. With none, the read gives nothing and sends nothing.

sortKey SortKeyCondition

The condition on the sort key of the index, the same for all partitions, or the default value to read them whole.

Returns

FanOutQueryCommand<Item>

The command.

Type Parameters

TEntity

The entity the keys belong to.

Exceptions

ArgumentNullException

partitionKeys is null.

ArgumentException

A partition key is the default value, was built for another attribute or occurs twice, which the message places by position, or there is a condition on a sort key and the index has none.

Query<T>(Index<T>, PartitionKey<T>, SortKeyCondition)

Starts a query of one partition of an index by a typed key: byStatus.Query(Order.Keys.ByStatusPk.Of(status)). The key of another entity is a compile error. The partition key of the table is of the same type, so that one fails here, see PartitionKey<TEntity>, unless the index has that attribute as well. See Index<T> for what is different about reading an index.

public static QueryCommand<T> Query<T>(this Index<T> index, PartitionKey<T> partitionKey, SortKeyCondition sortKey = default) where T : IDynamoDbEntity<T>

Parameters

index Index<T>

The index.

partitionKey PartitionKey<T>

The partition key of the index.

sortKey SortKeyCondition

The condition on the sort key of the index, or the default value to read the whole partition.

Returns

QueryCommand<T>

The command.

Type Parameters

T

The entity.

Exceptions

ArgumentException

The key is the default value, it was built for another attribute, or there is a condition on a sort key and the index has none.

Query<T>(Index<T>, IEnumerable<PartitionKey<T>>, SortKeyCondition)

Starts a query of several partitions of an index by typed keys, merged by the sort key of the index. It costs at least one read per partition, see FanOutQueryCommand<T>.

public static FanOutQueryCommand<T> Query<T>(this Index<T> index, IEnumerable<PartitionKey<T>> partitionKeys, SortKeyCondition sortKey = default) where T : IDynamoDbEntity<T>

Parameters

index Index<T>

The index.

partitionKeys IEnumerable<PartitionKey<T>>

The partitions, enumerated once, here. Their order breaks ties between equal sort keys. With none, the read gives nothing and sends nothing.

sortKey SortKeyCondition

The condition on the sort key of the index, the same for all partitions, or the default value to read them whole.

Returns

FanOutQueryCommand<T>

The command.

Type Parameters

T

The entity.

Exceptions

ArgumentNullException

partitionKeys is null.

ArgumentException

A partition key is the default value, was built for another attribute or occurs twice, which the message places by position, or there is a condition on a sort key and the index has none.

Query<TEntity>(Table<Item>, PartitionKey<TEntity>, SortKeyCondition)

Starts a query of one partition of a table without a schema, by the key of any entity, for a mixed read: shop.Query(Order.Keys.Pk.Of(id)).Of<Customer, Order>().

public static QueryCommand<Item> Query<TEntity>(this Table<Item> table, PartitionKey<TEntity> partitionKey, SortKeyCondition sortKey = default) where TEntity : IDynamoDbEntity<TEntity>

Parameters

table Table<Item>

The table.

partitionKey PartitionKey<TEntity>

The partition key.

sortKey SortKeyCondition

The condition on the sort key, or the default value to read the whole partition.

Returns

QueryCommand<Item>

The command.

Type Parameters

TEntity

The entity the key belongs to.

Exceptions

ArgumentException

The key is the default value, it was built for another attribute, or there is a condition on a sort key and the table has none.

Query<TEntity>(Table<Item>, IEnumerable<PartitionKey<TEntity>>, SortKeyCondition)

Starts a query of several partitions of a table without a schema, by the keys of any entity. It costs at least one read per partition, see FanOutQueryCommand<T>.

public static FanOutQueryCommand<Item> Query<TEntity>(this Table<Item> table, IEnumerable<PartitionKey<TEntity>> partitionKeys, SortKeyCondition sortKey = default) where TEntity : IDynamoDbEntity<TEntity>

Parameters

table Table<Item>

The table.

partitionKeys IEnumerable<PartitionKey<TEntity>>

The partitions, enumerated once, here. Their order breaks ties between equal sort keys. With none, the read gives nothing and sends nothing.

sortKey SortKeyCondition

The condition on the sort key, the same for all partitions, or the default value to read them whole.

Returns

FanOutQueryCommand<Item>

The command.

Type Parameters

TEntity

The entity the keys belong to.

Exceptions

ArgumentNullException

partitionKeys is null.

ArgumentException

A partition key is the default value, was built for another attribute or occurs twice, which the message places by position, or there is a condition on a sort key and the table has none.

Query<T>(Table<T>, PartitionKey<T>, SortKeyCondition)

Starts a query of one partition by a typed key: orders.Query(Order.Keys.Pk.Of(id), Order.Keys.Sk.BeginsWith()). The key of another entity is a compile error, and the key is formatted as the entity stores it.

public static QueryCommand<T> Query<T>(this Table<T> table, PartitionKey<T> partitionKey, SortKeyCondition sortKey = default) where T : IDynamoDbEntity<T>

Parameters

table Table<T>

The table.

partitionKey PartitionKey<T>

The partition key.

sortKey SortKeyCondition

The condition on the sort key, or the default value to read the whole partition.

Returns

QueryCommand<T>

The command.

Type Parameters

T

The entity.

Exceptions

ArgumentException

The key is the default value, it was built for another attribute, or there is a condition on a sort key and the table has none.

Query<T>(Table<T>, IEnumerable<PartitionKey<T>>, SortKeyCondition)

Starts a query of several partitions by typed keys, merged by sort key: orders.Query(shards.Select(Order.Keys.Pk.Of)). It costs at least one read per partition, see FanOutQueryCommand<T>.

public static FanOutQueryCommand<T> Query<T>(this Table<T> table, IEnumerable<PartitionKey<T>> partitionKeys, SortKeyCondition sortKey = default) where T : IDynamoDbEntity<T>

Parameters

table Table<T>

The table.

partitionKeys IEnumerable<PartitionKey<T>>

The partitions, enumerated once, here. Their order breaks ties between equal sort keys. With none, the read gives nothing and sends nothing.

sortKey SortKeyCondition

The condition on the sort key, the same for all partitions, or the default value to read them whole.

Returns

FanOutQueryCommand<T>

The command.

Type Parameters

T

The entity.

Exceptions

ArgumentNullException

partitionKeys is null.

ArgumentException

A partition key is the default value, was built for another attribute or occurs twice, which the message places by position, or there is a condition on a sort key and the table has none.