简体   繁体   中英

AWS DynamoDb Transactions in C#

I need to implement a transaction in C# with AWS DynamoDb as database

I checked the official website but don't see any example with C#

Below are my different Db operations.

 public class DbHandler
 {
     private readonly IConfiguration _configuration;
     private readonly RegionEndpoint _region;
     private readonly AmazonDynamoDBClient _dynamoClient; 

    public DbHandler(IConfiguration configuration)
     {
         _configuration = configuration;
         var awsSettings = configuration.GetSection("AWS:DynamoDb");
         _region = RegionEndpoint.GetBySystemName(awsSettings["Region"]);
         _dynamoClient = SetDynamoClient(awsSettings);
     }

     public async Task<EventTO> Add(EventTO eventObj)
     {
         try
         {
             //Db Operation#1
             await _dynamoClient.PutItemAsync(
             tableName: _configuration.GetSection("AWS:DynamoDb")["Table1"],
             item: SetEventObject(eventObj));

             //Db Operation#2
             await _dynamoClient.PutItemAsync(tableName: _configuration.GetSection("AWS:DynamoDb")["Table2"], someotherObj);
             return eventObj;
         }
         catch (Exception ex)
         {
             throw;
         }

     }
 }

I am using the Low Level API

    private Dictionary<string, AttributeValue> SetEventObject(EventTO eventObj)
        {
            //DynamoDb - Using Low Level API
            var attributes = new Dictionary<string, AttributeValue>
            {
                //EventId
                {
                    nameof(eventObj.EventId),
                    new AttributeValue
                    {
                        S =eventObj.EventId
                    }
                },
                //Event Title
                {
                    nameof(eventObj.Title),
                    new AttributeValue
                    {
                        S = eventObj.Title.Trim()
                    }
                }
            };
            return attributes;
        }

I want to know how to implement Transaction using the Low Level API in C# for AWS DynamoDb?

Thanks!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM