Home > Back-end >  Is there a .NET equivalent of DynamoDBMapper?
Is there a .NET equivalent of DynamoDBMapper?

Time:08-30

I'd like to construct a CreateTableRequest object from data annotations in a class. It looks like Amazon provides DynamoDBMapper in the Java SDK, which makes this process simple.

How can I do the same in .NET/C#?

 AmazonDynamoDB dynamoDBClient = new AmazonDynamoDBClient();
 DynamoDBMapper mapper = new DynamoDBMapper(dynamoDBClient);
 CreateTableRequest req = mapper.generateCreateTableRequest(TestClass.class);
 // Table provision throughput is still required since it cannot be specified in your POJO
 req.setProvisionedThroughput(new ProvisionedThroughput(5L, 5L));
 // Fire off the CreateTableRequest using the low-level client
 dynamoDBClient.createTable(req);

CodePudding user response:

generateCreateTableRequest is unique to the Java SDK with no equivalent (yet) for the .NET SDK.

The general .NET equivalent for Java's DynamoDBMapper is the DynamoDBContext class (docs 1, docs 2). This class provides a high-level .NET object persistence model that enables you to map your client-side classes to Amazon DynamoDB tables.

However, as per docs:

The object persistence model does not provide an API to create, update, or delete tables. It provides only data operations. You can use only the AWS SDK for .NET low-level API to create, update, and delete tables.

You will have to use the low-level .NET API to create tables.

  • Related