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
tableTable<T>The table.
entityTThe entity to take the key and the version from.
Returns
- DeleteCommand<T>
The command.
Type Parameters
TThe 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
entityis 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
tableTable<T>The table.
entityTThe entity to take the key from.
Returns
- GetCommand<T>
The command.
Type Parameters
TThe entity.
Exceptions
- ArgumentNullException
entityis 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
Returns
Type Parameters
TEntityThe 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
Returns
- Index<T>
The index.
Type Parameters
TThe 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
indexIndex<T>The index.
sortKeySortKeyConditionThe condition on the sort key of the index, or the default value to read the whole partition.
Returns
- QueryCommand<T>
The command.
Type Parameters
TThe 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
indexis null.- InvalidOperationException
Thas 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
indexIndex<Item>The index.
partitionKeyPartitionKey<TEntity>The partition key of the index.
sortKeySortKeyConditionThe condition on the sort key of the index, or the default value to read the whole partition.
Returns
- QueryCommand<Item>
The command.
Type Parameters
TEntityThe 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
indexIndex<Item>The index.
partitionKeysIEnumerable<PartitionKey<TEntity>>The partitions, enumerated once, here. Their order breaks ties between equal sort keys. With none, the read gives nothing and sends nothing.
sortKeySortKeyConditionThe 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
TEntityThe entity the keys belong to.
Exceptions
- ArgumentNullException
partitionKeysis 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
indexIndex<T>The index.
partitionKeyPartitionKey<T>The partition key of the index.
sortKeySortKeyConditionThe condition on the sort key of the index, or the default value to read the whole partition.
Returns
- QueryCommand<T>
The command.
Type Parameters
TThe 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
indexIndex<T>The index.
partitionKeysIEnumerable<PartitionKey<T>>The partitions, enumerated once, here. Their order breaks ties between equal sort keys. With none, the read gives nothing and sends nothing.
sortKeySortKeyConditionThe 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
TThe entity.
Exceptions
- ArgumentNullException
partitionKeysis 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
tableTable<Item>The table.
partitionKeyPartitionKey<TEntity>The partition key.
sortKeySortKeyConditionThe condition on the sort key, or the default value to read the whole partition.
Returns
- QueryCommand<Item>
The command.
Type Parameters
TEntityThe 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
tableTable<Item>The table.
partitionKeysIEnumerable<PartitionKey<TEntity>>The partitions, enumerated once, here. Their order breaks ties between equal sort keys. With none, the read gives nothing and sends nothing.
sortKeySortKeyConditionThe 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
TEntityThe entity the keys belong to.
Exceptions
- ArgumentNullException
partitionKeysis 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
tableTable<T>The table.
partitionKeyPartitionKey<T>The partition key.
sortKeySortKeyConditionThe condition on the sort key, or the default value to read the whole partition.
Returns
- QueryCommand<T>
The command.
Type Parameters
TThe 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
tableTable<T>The table.
partitionKeysIEnumerable<PartitionKey<T>>The partitions, enumerated once, here. Their order breaks ties between equal sort keys. With none, the read gives nothing and sends nothing.
sortKeySortKeyConditionThe 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
TThe entity.
Exceptions
- ArgumentNullException
partitionKeysis 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.