使用文档模型拉取完整的 dynamodb table

Pull full dynamodb table with document model

string tableName = _awsSettings.TableSettings.Table + _awsSettings.TableSettings.Suffix;
Table table = Table.LoadTable(_amazonDynamoDb, tableName);

DocumentBatchGet batch = table.CreateBatchGet();
await batch.ExecuteAsync();
List<Document> results = batch.Results;
return results.As<Lab>();

以上代码returns 0个结果。我希望 return 整个 table。

如何使用文档模型 (Table.LoadTable) 提取整个 table?

Table.LoadTable() method returns a Table 对象,它基本上是 DynamoDB 客户端的包装器。该对象不包含 AWS 中实际 table 中的任何数据。

要阅读 table 中的所有项目,您需要使用 Table.Scan() 方法。下面是一些使用 scan 将 table 的内容转储到标准输出的示例代码。

    private static void DumpTable(Table table)
    {
        ScanFilter scanFilter = new ScanFilter();

        Search search = productCatalogTable.Scan(scanFilter);

        List<Document> documentList = new List<Document>();
        do
        {
            documentList = search.GetNextSet();
            foreach (var document in documentList)
                PrintDocument(document);
        } while (!search.IsDone);
    }

    private static void PrintDocument(Document document)
    {
        //   count++;
        Console.WriteLine();
        foreach (var attribute in document.GetAttributeNames())
        {
            string stringValue = null;
            var value = document[attribute];
            if (value is Primitive)
                stringValue = value.AsPrimitive().Value.ToString();
            else if (value is PrimitiveList)
                stringValue = string.Join(",", (from primitive
                                in value.AsPrimitiveList().Entries
                                                select primitive.Value).ToArray());
            Console.WriteLine("{0} - {1}", attribute, stringValue);
        }
    }

此 C# 代码用于使用 BatchGet 或 CreateBatchGet

从具有不同 guid 的 dynamodb table 中提取记录
        string tablename = "AnyTableName"; //table whose data you want to fetch

        var BatchRead = ABCContext.Context.CreateBatchGet<ABCTable>(  

            new DynamoDBOperationConfig
            {
                OverrideTableName = tablename; 
            });

        foreach(string Id in IdList) // in case you are taking string from input
        {
            Guid objGuid = Guid.Parse(Id); //parsing string to guid
            BatchRead.AddKey(objGuid);
        }

        await BatchRead.ExecuteAsync();
        var result = BatchRead.Results;

// ABCTable 是 table 模式,用于在 dynamodb 中创建和要获取的数据