c# - DynamoDB .NET - 从表中删除所有项目

标签 c# .net amazon-dynamodb dml

我正在学习如何使用 DynamoDB for .net,我有一个疑问,是否有从现有表中删除所有项目的正确方法?我的意思是,我不想删除表,只是清空它。 我读过有关批处理的信息,但它们对我帮助不大。

我有这个

private string DeleteAllFromTable()
    {
        string result = string.Empty;

        try
        {

            var request = new BatchWriteItemRequest
            {
                RequestItems = new Dictionary<string, List<WriteRequest>> 
                { 
                    {
                        this.Tablename, new List<WriteRequest>
                        {
                            new WriteRequest
                            {
                                DeleteRequest = new DeleteRequest
                                {
                                    Key = new Dictionary<string,AttributeValue>()
                                    {
                                        { "Id", new AttributeValue { S = "a" } }
                                    }
                                }
                            }
                        }
                    }
                }
            };

            var response = this.DynamoDBClient.BatchWriteItem(request);

        }
        catch (AmazonDynamoDBException e)
        {

        }


        return result;
    }

当然,那只会删除与值“a”匹配的 id。

谢谢。

最佳答案

我建议您只删除表并重新创建它。来自 DynamoDB Guidelines for Working with Tables documentation :

...

Deleting an entire table is significantly more efficient than removing items one-by-one, which essentially doubles the write throughput as you do as many delete operations as put operations.

关于c# - DynamoDB .NET - 从表中删除所有项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30733640/

相关文章:

c# - json.net反序列化为对象数组c#

c# - 如何以最快的方式做到这一点?图像阵列

c# - 尝试显示 ListView 中的默认选定值

c# - 如何在 C# 中获取窗口的图标

ios - 如何找到 Cognito 池 ID

c# - 我可以允许匿名用户和事件目录用户浏览同一个 IIS 7.5 站点吗?

c# - 找出用户属于哪个组

c# - .Net 桌面应用程序和 Web 应用程序之间的技术区别是什么?

java - SpringBoot - Java AWS SDK 2 DynamoDB Enhanced Client 和 devtools 问题

amazon-web-services - 跨两个不同的 AWS 账户将数据从 DynamoDB 复制到 Redshift 中?