Table of Contents

Class DynamoDBContext

Namespace
Amazon.DynamoDBv2.DataModel
Assembly
AWSSDK.DynamoDBv2.dll

Context object for using the DataModel mode of DynamoDB. Used to interact with the service, save/load objects, etc.

public class DynamoDBContext : IDynamoDBContext, IDisposable
Inheritance
DynamoDBContext
Implements
Inherited Members

Constructors

DynamoDBContext(IAmazonDynamoDB)

Constructs a DynamoDBContext object with the specified DynamoDB client. Uses default DynamoDBContextConfig object for configuration.

public DynamoDBContext(IAmazonDynamoDB client)

Parameters

client IAmazonDynamoDB

Client to use for making calls

DynamoDBContext(IAmazonDynamoDB, DynamoDBContextConfig)

Constructs a DynamoDBContext object with the specified DynamoDB client and configuration.

public DynamoDBContext(IAmazonDynamoDB client, DynamoDBContextConfig config)

Parameters

client IAmazonDynamoDB

Client to use for making calls

config DynamoDBContextConfig

Configuration to use

Properties

ConverterCache

This cache is a way to store Converters for objects which provides a way to expand Context

public Dictionary<Type, IPropertyConverter> ConverterCache { get; }

Property Value

Dictionary<Type, IPropertyConverter>

Methods

CreateBatchGet<T>()

Creates a strongly-typed BatchGet object, allowing a batch-get operation against DynamoDB.

public BatchGet<T> CreateBatchGet<T>()

Returns

BatchGet<T>

Empty strongly-typed BatchGet object

Type Parameters

T

Type of objects to get

CreateBatchGet<T>(DynamoDBOperationConfig)

Creates a strongly-typed BatchGet object, allowing a batch-get operation against DynamoDB.

public BatchGet<T> CreateBatchGet<T>(DynamoDBOperationConfig operationConfig)

Parameters

operationConfig DynamoDBOperationConfig

Config object which can be used to override that table used.

Returns

BatchGet<T>

Empty strongly-typed BatchGet object

Type Parameters

T

Type of objects to get

CreateBatchWrite<T>()

Creates a strongly-typed BatchWrite object, allowing a batch-write operation against DynamoDB.

public BatchWrite<T> CreateBatchWrite<T>()

Returns

BatchWrite<T>

Empty strongly-typed BatchWrite object

Type Parameters

T

Type of objects to write

CreateBatchWrite<T>(DynamoDBOperationConfig)

Creates a strongly-typed BatchWrite object, allowing a batch-write operation against DynamoDB.

public BatchWrite<T> CreateBatchWrite<T>(DynamoDBOperationConfig operationConfig)

Parameters

operationConfig DynamoDBOperationConfig

Config object which can be used to override that table used.

Returns

BatchWrite<T>

Empty strongly-typed BatchWrite object

Type Parameters

T

Type of objects to write

CreateMultiTableBatchGet(params BatchGet[])

Creates a MultiTableBatchGet object, composed of multiple individual BatchGet objects.

public MultiTableBatchGet CreateMultiTableBatchGet(params BatchGet[] batches)

Parameters

batches BatchGet[]

Individual BatchGet objects

Returns

MultiTableBatchGet

Composite MultiTableBatchGet object

CreateMultiTableBatchWrite(params BatchWrite[])

Creates a MultiTableBatchWrite object, composed of multiple individual BatchWrite objects.

public MultiTableBatchWrite CreateMultiTableBatchWrite(params BatchWrite[] batches)

Parameters

batches BatchWrite[]

Individual BatchWrite objects

Returns

MultiTableBatchWrite

Composite MultiTableBatchWrite object

DeleteAsync<T>(object, DynamoDBOperationConfig, CancellationToken)

Initiates the asynchronous execution of the Delete operation. Amazon.DynamoDBv2.DataModel.DynamoDBContext.Delete

public Task DeleteAsync<T>(object hashKey, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default)

Parameters

hashKey object

Hash key element of the object to delete.

operationConfig DynamoDBOperationConfig

Config object which can be used to override that table used.

cancellationToken CancellationToken

Token which can be used to cancel the task.

Returns

Task

A Task that can be used to poll or wait for results, or both.

Type Parameters

T

Type of object.

DeleteAsync<T>(object, object, DynamoDBOperationConfig, CancellationToken)

Initiates the asynchronous execution of the Delete operation. Amazon.DynamoDBv2.DataModel.DynamoDBContext.Delete

public Task DeleteAsync<T>(object hashKey, object rangeKey, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default)

Parameters

hashKey object

Hash key element of the object to delete.

rangeKey object

Range key element of the object to delete.

operationConfig DynamoDBOperationConfig

Config object which can be used to override that table used.

cancellationToken CancellationToken

Token which can be used to cancel the task.

Returns

Task

A Task that can be used to poll or wait for results, or both.

Type Parameters

T

Type of object.

DeleteAsync<T>(object, object, CancellationToken)

Initiates the asynchronous execution of the Delete operation. Amazon.DynamoDBv2.DataModel.DynamoDBContext.Delete

public Task DeleteAsync<T>(object hashKey, object rangeKey, CancellationToken cancellationToken = default)

Parameters

hashKey object

Hash key element of the object to delete.

rangeKey object

Range key element of the object to delete.

cancellationToken CancellationToken

Token which can be used to cancel the task.

Returns

Task

A Task that can be used to poll or wait for results, or both.

Type Parameters

T

Type of object.

DeleteAsync<T>(object, CancellationToken)

Initiates the asynchronous execution of the Delete operation. Amazon.DynamoDBv2.DataModel.DynamoDBContext.Delete

public Task DeleteAsync<T>(object hashKey, CancellationToken cancellationToken = default)

Parameters

hashKey object

Hash key element of the object to delete.

cancellationToken CancellationToken

Token which can be used to cancel the task.

Returns

Task

A Task that can be used to poll or wait for results, or both.

Type Parameters

T

Type of object.

DeleteAsync<T>(T, DynamoDBOperationConfig, CancellationToken)

Initiates the asynchronous execution of the Delete operation. Amazon.DynamoDBv2.DataModel.DynamoDBContext.Delete

public Task DeleteAsync<T>(T value, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default)

Parameters

value T

Object to delete.

operationConfig DynamoDBOperationConfig

Overriding configuration.

cancellationToken CancellationToken

Token which can be used to cancel the task.

Returns

Task

A Task that can be used to poll or wait for results, or both.

Type Parameters

T

Type of object.

DeleteAsync<T>(T, CancellationToken)

Initiates the asynchronous execution of the Delete operation. Amazon.DynamoDBv2.DataModel.DynamoDBContext.Delete

public Task DeleteAsync<T>(T value, CancellationToken cancellationToken = default)

Parameters

value T

Object to delete.

cancellationToken CancellationToken

Token which can be used to cancel the task.

Returns

Task

A Task that can be used to poll or wait for results, or both.

Type Parameters

T

Type of object.

Dispose()

Disposes of all managed and unmanaged resources.

public void Dispose()

Dispose(bool)

Implements the Dispose pattern

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

Whether this object is being disposed via a call to Dispose or garbage collected.

ExecuteBatchGetAsync(params BatchGet[])

Issues a batch-get request with multiple batches.

Results are stored in the individual batches.

public Task ExecuteBatchGetAsync(params BatchGet[] batches)

Parameters

batches BatchGet[]

Configured BatchGet objects

Returns

Task

ExecuteBatchGetAsync(BatchGet[], CancellationToken)

Issues a batch-get request with multiple batches.

Results are stored in the individual batches.

public Task ExecuteBatchGetAsync(BatchGet[] batches, CancellationToken cancellationToken = default)

Parameters

batches BatchGet[]

Configured BatchGet objects

cancellationToken CancellationToken

A cancellation token that can be used by other objects or threads to receive notice of cancellation.

Returns

Task

ExecuteBatchWriteAsync(BatchWrite[], CancellationToken)

Issues a batch-write request with multiple batches.

public Task ExecuteBatchWriteAsync(BatchWrite[] batches, CancellationToken cancellationToken = default)

Parameters

batches BatchWrite[]

Configured BatchWrite objects

cancellationToken CancellationToken

A cancellation token that can be used by other objects or threads to receive notice of cancellation.

Returns

Task

~DynamoDBContext()

The destructor for the client class.

protected ~DynamoDBContext()

FromDocument<T>(Document)

Deserializes a document to an instance of type T.

public T FromDocument<T>(Document document)

Parameters

document Document

Document with properties to use.

Returns

T

Object of type T, populated with properties from the document.

Type Parameters

T

Type to populate.

FromDocument<T>(Document, DynamoDBOperationConfig)

Deserializes a document to an instance of type T.

public T FromDocument<T>(Document document, DynamoDBOperationConfig operationConfig)

Parameters

document Document

Document with properties to use.

operationConfig DynamoDBOperationConfig

Config object which can be used to override the table used.

Returns

T

Object of type T, populated with properties from the document.

Type Parameters

T

Type to populate.

FromDocuments<T>(IEnumerable<Document>)

Deserializes a collections of documents to a collection of instances of type T.

public IEnumerable<T> FromDocuments<T>(IEnumerable<Document> documents)

Parameters

documents IEnumerable<Document>

Documents to deserialize.

Returns

IEnumerable<T>

Collection of items of type T, each populated with properties from a corresponding document.

Type Parameters

T

Type to populate.

FromDocuments<T>(IEnumerable<Document>, DynamoDBOperationConfig)

Deserializes a collections of documents to a collection of instances of type T.

public IEnumerable<T> FromDocuments<T>(IEnumerable<Document> documents, DynamoDBOperationConfig operationConfig)

Parameters

documents IEnumerable<Document>

Documents to deserialize.

operationConfig DynamoDBOperationConfig

Config object which can be used to override the table used.

Returns

IEnumerable<T>

Collection of items of type T, each populated with properties from a corresponding document.

Type Parameters

T

Type to populate.

FromQueryAsync<T>(QueryOperationConfig, DynamoDBOperationConfig)

Configures an async Query operation against DynamoDB, finding items that match the specified conditions.

public AsyncSearch<T> FromQueryAsync<T>(QueryOperationConfig queryConfig, DynamoDBOperationConfig operationConfig = null)

Parameters

queryConfig QueryOperationConfig

Query request object.

operationConfig DynamoDBOperationConfig

Config object which can be used to override the table used.

Returns

AsyncSearch<T>

AsyncSearch which can be used to retrieve DynamoDB data.

Type Parameters

T

Type of object.

FromScanAsync<T>(ScanOperationConfig, DynamoDBOperationConfig)

Configures an async Scan operation against DynamoDB, finding items that match the specified conditions.

public AsyncSearch<T> FromScanAsync<T>(ScanOperationConfig scanConfig, DynamoDBOperationConfig operationConfig = null)

Parameters

scanConfig ScanOperationConfig

Scan request object.

operationConfig DynamoDBOperationConfig

Config object which can be used to override the table used.

Returns

AsyncSearch<T>

AsyncSearch which can be used to retrieve DynamoDB data.

Type Parameters

T

Type of object.

GetTargetTable<T>(DynamoDBOperationConfig)

Retrieves the target table for the specified type

public Table GetTargetTable<T>(DynamoDBOperationConfig operationConfig = null)

Parameters

operationConfig DynamoDBOperationConfig

Returns

Table

Table object

Type Parameters

T

Type to retrieve table for

LoadAsync<T>(object, DynamoDBOperationConfig, CancellationToken)

Initiates the asynchronous execution of the Load operation. Amazon.DynamoDBv2.DataModel.DynamoDBContext.Load

public Task<T> LoadAsync<T>(object hashKey, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default)

Parameters

hashKey object

Hash key element of the target item.

operationConfig DynamoDBOperationConfig

Overriding configuration.

cancellationToken CancellationToken

Token which can be used to cancel the task.

Returns

Task<T>

A Task that can be used to poll or wait for results, or both.

Type Parameters

T

Type to populate.

LoadAsync<T>(object, object, DynamoDBOperationConfig, CancellationToken)

Initiates the asynchronous execution of the Load operation. Amazon.DynamoDBv2.DataModel.DynamoDBContext.Load

public Task<T> LoadAsync<T>(object hashKey, object rangeKey, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default)

Parameters

hashKey object

Hash key element of the target item.

rangeKey object

Range key element of the target item.

operationConfig DynamoDBOperationConfig

Overriding configuration.

cancellationToken CancellationToken

Token which can be used to cancel the task.

Returns

Task<T>

A Task that can be used to poll or wait for results, or both.

Type Parameters

T

Type to populate.

LoadAsync<T>(object, object, CancellationToken)

Initiates the asynchronous execution of the Load operation. Amazon.DynamoDBv2.DataModel.DynamoDBContext.Load

public Task<T> LoadAsync<T>(object hashKey, object rangeKey, CancellationToken cancellationToken = default)

Parameters

hashKey object

Hash key element of the target item.

rangeKey object

Range key element of the target item.

cancellationToken CancellationToken

Token which can be used to cancel the task.

Returns

Task<T>

A Task that can be used to poll or wait for results, or both.

Type Parameters

T

Type to populate.

LoadAsync<T>(object, CancellationToken)

Initiates the asynchronous execution of the Load operation. Amazon.DynamoDBv2.DataModel.DynamoDBContext.Load

public Task<T> LoadAsync<T>(object hashKey, CancellationToken cancellationToken = default)

Parameters

hashKey object

Hash key element of the target item.

cancellationToken CancellationToken

Token which can be used to cancel the task.

Returns

Task<T>

A Task that can be used to poll or wait for results, or both.

Type Parameters

T

Type to populate.

LoadAsync<T>(T, DynamoDBOperationConfig, CancellationToken)

Initiates the asynchronous execution of the Load operation. Amazon.DynamoDBv2.DataModel.DynamoDBContext.Load

public Task<T> LoadAsync<T>(T keyObject, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default)

Parameters

keyObject T

Key of the target item.

operationConfig DynamoDBOperationConfig

Overriding configuration.

cancellationToken CancellationToken

Token which can be used to cancel the task.

Returns

Task<T>

A Task that can be used to poll or wait for results, or both.

Type Parameters

T

Type to populate.

LoadAsync<T>(T, CancellationToken)

Initiates the asynchronous execution of the Load operation. Amazon.DynamoDBv2.DataModel.DynamoDBContext.Load

public Task<T> LoadAsync<T>(T keyObject, CancellationToken cancellationToken = default)

Parameters

keyObject T

Key of the target item.

cancellationToken CancellationToken

Token which can be used to cancel the task.

Returns

Task<T>

A Task that can be used to poll or wait for results, or both.

Type Parameters

T

Type to populate.

QueryAsync<T>(object, DynamoDBOperationConfig)

Configures an async Query operation against DynamoDB, finding items that match the specified hash primary key.

public AsyncSearch<T> QueryAsync<T>(object hashKeyValue, DynamoDBOperationConfig operationConfig = null)

Parameters

hashKeyValue object

Hash key of the items to query.

operationConfig DynamoDBOperationConfig

Config object which can be used to override the table used.

Returns

AsyncSearch<T>

AsyncSearch which can be used to retrieve DynamoDB data.

Type Parameters

T

Type of object.

QueryAsync<T>(object, QueryOperator, IEnumerable<object>, DynamoDBOperationConfig)

Configures an async Query operation against DynamoDB, finding items that match the specified range element condition for a hash-and-range primary key.

public AsyncSearch<T> QueryAsync<T>(object hashKeyValue, QueryOperator op, IEnumerable<object> values, DynamoDBOperationConfig operationConfig = null)

Parameters

hashKeyValue object

Hash key of the items to query.

op QueryOperator

Operation of the condition.

values IEnumerable<object>

Value(s) of the condition. For all operations except QueryOperator.Between, values should be one value. For QueryOperator.Between, values should be two values.

operationConfig DynamoDBOperationConfig

Config object which can be used to override the table used.

Returns

AsyncSearch<T>

AsyncSearch which can be used to retrieve DynamoDB data.

Type Parameters

T

Type of object.

SaveAsync<T>(T, DynamoDBOperationConfig, CancellationToken)

Initiates the asynchronous execution of the Save operation. Amazon.DynamoDBv2.DataModel.DynamoDBContext.Save

public Task SaveAsync<T>(T value, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default)

Parameters

value T

Object to save.

operationConfig DynamoDBOperationConfig

Overriding configuration.

cancellationToken CancellationToken

Token which can be used to cancel the task.

Returns

Task

A Task that can be used to poll or wait for results, or both.

Type Parameters

T

Type to save as.

SaveAsync<T>(T, CancellationToken)

Initiates the asynchronous execution of the Save operation. Amazon.DynamoDBv2.DataModel.DynamoDBContext.Save

public Task SaveAsync<T>(T value, CancellationToken cancellationToken = default)

Parameters

value T

Object to save.

cancellationToken CancellationToken

Token which can be used to cancel the task.

Returns

Task

A Task that can be used to poll or wait for results, or both.

Type Parameters

T

Type to save as.

ScanAsync<T>(IEnumerable<ScanCondition>, DynamoDBOperationConfig)

Configures an async Scan operation against DynamoDB, finding items that match the specified conditions.

public AsyncSearch<T> ScanAsync<T>(IEnumerable<ScanCondition> conditions, DynamoDBOperationConfig operationConfig = null)

Parameters

conditions IEnumerable<ScanCondition>

Conditions that the results should meet.

operationConfig DynamoDBOperationConfig

Config object which can be used to override that table used.

Returns

AsyncSearch<T>

AsyncSearch which can be used to retrieve DynamoDB data.

Type Parameters

T

Type of object.

ToDocument<T>(T)

Serializes an object to a Document.

public Document ToDocument<T>(T value)

Parameters

value T

Object to serialize.

Returns

Document

Document with attributes populated from object.

Type Parameters

T

Type to serialize as.

ToDocument<T>(T, DynamoDBOperationConfig)

Serializes an object to a Document.

public Document ToDocument<T>(T value, DynamoDBOperationConfig operationConfig)

Parameters

value T

Object to serialize.

operationConfig DynamoDBOperationConfig

Config object which can be used to override the table used.

Returns

Document

Document with attributes populated from object.

Type Parameters

T

Type to serialize as.