Amazon DynamoDB
Developer Guide (API Version 2012-08-10)
« PreviousNext »
View the PDF for this guide.Go to the AWS Discussion Forum for this product.Go to the Kindle Store to download this guide in Kindle format.Did this page help you?  Yes | No |  Tell us about it...

Amazon DynamoDB Attributes

The following table lists the attributes the object persistence model offers so you can map your classes and properties to Amazon DynamoDB tables and attributes.

Note

In the following table, only DynamoDBTable and DynamoDBHashKey are required tags.

Declarative Tag (attribute)Description
DynamoDBHashKey

Maps a class property to the hash attribute of the table's primary key. The primary key attributes cannot be a collection type.

The following C# code examples maps the Book class to the ProductCatalog table, and the Id property to the table's primary key hash attribute.

[DynamoDBTable("ProductCatalog")] 
   public class Book { 
   [DynamoDBHashKey] 
   public int Id { get; set; }
  
   // Additional properties go here. 
}

DynamoDBIgnore

Indicates DynamoDBContext that the associated property should be ignored. If you don't want to save any of your class properties you can add this attribute to instruct DynamoDBContext not to include this property when saving objects to the table.

DynamoDBProperty

Maps a class property to a table attribute. If the class property maps to the same name table attribute, then you don't need to specify this attribute. However, if the names are not the same, you can use this tag to provide the mapping. In the following C# statement the DynamoDBProperty maps the BookAuthors property to the Authors attribute in the table.

[DynamoDBProperty("Authors")]    
public List<string> BookAuthors { get; set; }

DynamoDBContext uses this mapping information to create the Authors attribute when saving object data to the corresponding table.

DynamoDBRangeKey

Maps a class property to the range attribute of the table's primary key. If the table's primary key is made of both the hash and range attributes, you must specify both the DynamoDBHashKey and DynamoDBRangeKey attributes in your class mapping.

For example, the sample table Reply has a primary key made of the Id hash attribute and Replenishment range attribute. The following C# code example maps the Reply class to the Reply table. The class definition also indicates that two of its properties map to the primary key.

For more information about sample tables, see Example Tables and Data in Amazon DynamoDB.

[DynamoDBTable("Reply")] 
public class Reply { 
   [DynamoDBHashKey] 
   public int ThreadId { get; set; }
   [DynamoDBRangeKey]
   public string Replenishment { get; set; }
   // Additional properties go here. 
}

DynamoDBTable

Identifies the target table in Amazon DynamoDB to which the class maps. For example, the following C# code example maps the Developer class to the People table in Amazon DynamoDB.

[DynamoDBTable("People")] 
public class Developer { ...}

This attribute can be inherited or overridden.

  • The DynamoDBTable attribute can be inherited. In the preceding example, if you add a new class, Lead, that inherits from the Developer class, it also maps to the People table. Both the Developer and Lead objects are stored in the People table.

  • The DynamoDBTable attribute can also be overridden. In the following C# code example, the Manager class inherits from the Developer class, however the explicit addition of the DynamoDBTable attribute maps the class to another table (Managers).

    [DynamoDBTable("Managers")] 
    public class Manager : Developer { ...}

You can add the optional parameter, LowerCamelCaseProperties, to request Amazon DynamoDB to lower case the first letter of the property name when storing the objects to a table as shown in the following C# snippet.

[DynamoDBTable("People", LowerCamelCaseProperties=true)] 
public class Developer { 
   string DeveloperName;
   ...}

When saving instances of the Developer class, DynamoDBContext saves the DeveloperName property as the developerName.

DynamoDBVersionIdentifies a class property for storing the item version number. To more information about versioning, see Optimistic Locking Using Version Number with Amazon DynamoDB Using the AWS SDK for .NET Object Persistence Model.