Skip to content

Latest commit

 

History

History
89 lines (63 loc) · 3.98 KB

File metadata and controls

89 lines (63 loc) · 3.98 KB

CRUD operations with Data Model API

The Data Model api uses .NET classes to model data that will be stored in and retrieved from DynamoDB. For the TODO list application a list is modeled by the TODOList class which contains a collection of TODOListItem for each task in the list.

Context Object

The DynamoDBContext object is used to save and load .NET objects from DynamoDB. DynamoDBContext takes care of translating the data from the properties on the TODOList and TODOListItem to the service clients AttributeValue objects.

Property DynamoDB Type
User S
ListId S
Complete BOOL
CreateDate S
UpdateDate S
Items L<M>
-> TODOListItem.Description S
-> TODOListItem.AssignedEmail S
-> TODOListItem.Complete BOOL

Note: In this example the DynamoDBContextConfig.Conversion is set to DynamoDBEntryConversion.V2. This should be set for all new applications as it supports the BOOL, L and M DynamoDB types. The original V1 conversion was created before those types existed and switching the default to V2 would be a breaking change to existing users.

Save a TODO List

To save a TODOList we need to create the TODOList object and then call the SaveAsync method on the context.

Load a TODO List

To load an object we need to call the LoadAsync method passing in the values for the key.

Query a user's TODO List

The QueryAsync returns back an AsyncSearch object. This object can be used to get a page of data over and over again by calling the GetNextSetAsync. Since we want all of the lists for the user we can skip dealing with pagination and call GetRemainingAsync to get all of the lists.

Delete a TODO List

To delete an object we need to call the DeleteAsync method passing in the values for the key.


Continue on to next page: Amazon DynamoDB wrap up