I am trying to use DynamoDB in Amazon AWS in my MVC .net project. And I am also trying to do a Business-DataAccess-Model layered project.
I have a GenericDataRepository class which implements an Add() functionality.
I am sending a T object to Add() and I would like to convert that to Amazon's Document object, dynamically. How can I do that and what is the best practice?
public void Add(T entity)
{
if (entity == null)
return;
var doc = new Document();
// Convert entity to Document automatically
doc["Title"] = entity.Title;
doc["Body"] = entity.Body;
doc["Author"] = entity.Author;
// Convert entity to Document automatically
.....
.....
.....
}
Yes, like all the other database management systems, DynamoDB also supports all the conditional operators, User can specify a condition that is satisfied for a put, update, or delete operation to work on an item.
marshall(data, options) ⇒ mapConvert a JavaScript object into a DynamoDB record. Examples: Convert a JavaScript object into a DynamoDB record.
To configure auto scaling in DynamoDB, you set the minimum and maximum levels of read and write capacity in addition to the target utilization percentage. Auto scaling uses Amazon CloudWatch to monitor a table's read and write capacity metrics. To do so, it creates CloudWatch alarms that track consumed capacity.
The DynamoDBMapper utility class makes it simple to store instances of this class in DynamoDB.
In a Latest version of aws dynamo db SDK. this feature is supported, you can achieve your goal without any hassle. Simple and Fast
public Document Add <T>(T entity, IAmazonDynamoDB dbClient)
{
Amazon.DynamoDBv2.DataModel.DynamoDBContext db = new Amazon.DynamoDBv2.DataModel.DynamoDBContext(dbClient);
Document document = db.ToDocument(entity);
return document;
}
I think you can use Json.net to serialize your object to json and then create dynamoDb document form it according to their docs:
var jsonText = JsonConvert.SerializeObject(entity, Formatting.Indented);
var item = Document.FromJson(jsonText);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With