0

Using .net core c# dynamo db

I was using the following method to save to my dynamo db:

public Task SaveAsync(T item)
{
    return base.SaveAsync(item, _config);
}

And then in my controller I call the above as:

foreach (var data in myData)
{
   //update data
  await _dynamoDbManager.SaveAsync(data);
}

The above works fine but instead of saving individually I want to save at one using batch.

I dont know how I can write a similar Batch method. I tried with below:

public Task CreateBatch()
{
   //The below is not correct as I dont know what to pass as <T> in below call.
   return CreateBatchWrite<T>(_config);
}

I want to create the above method so that I can use it as below in my controller:

var batchWriter =  CreateBatch();
foreach (var data in myData)
{
   //update data
}
batchWriter.AddPutItems(myData);
await batchWriter.ExecuteAsync();

Can anyone help in writing my CreateBatchWrite method.

1 Answer 1

1

You could create method as:

public BatchWrite<T> CreateBatch<T>()
{
   return CreateBatchWrite<T>(_config);
}

And then call this in your controller as:

var batchWriter =  CreateBatch<MyData>();
batchWriter.AddPutItems(myData);
await batchWriter.ExecuteAsync();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.