using PocoDynamo;
using Amazon.DynamoDBv2.DataModel;
// Define the POCO class for your table
[DynamoDBTable("MyTable")]
public class MyTableItem
{
[DynamoDBHashKey("MyTableItemId")]
public string Id { get; set; }
[DynamoDBProperty("MyTableItemName")]
public string Name { get; set; }
[DynamoDBGlobalSecondaryIndexRangeKey("MyTableItemDateIndex")]
public DateTime Date { get; set; }
}
// Initialize the DynamoDB client and PocoDynamo context
var client = new AmazonDynamoDBClient();
var context = new PocoDynamo(client);
// Define the properties for the global secondary index
var gsi = new GlobalSecondaryIndex
{
IndexName = "MyTableItemDateIndex",
KeySchema = new List<KeySchemaElement>
{
new KeySchemaElement("MyTableItemId", KeyType.HASH),
new KeySchemaElement("MyTableItemDateIndex", KeyType.RANGE)
},
Projection = new Projection { ProjectionType = ProjectionType.ALL },
ProvisionedThroughput = new ProvisionedThroughput { ReadCapacityUnits = 5, WriteCapacityUnits = 5 }
};
// Create the table with the global secondary index
context.CreateTablesIfNotExists<MyTableItem>(
new CreateTableRequest
{
ProvisionedThroughput = new ProvisionedThroughput { ReadCapacityUnits = 5, WriteCapacityUnits = 5 },
GlobalSecondaryIndexes = new List<GlobalSecondaryIndex> { gsi }
});
1条答案
按热度按时间cvxl0en21#
下面是我很久以前使用Poco创建的一个示例: