使用 DynamoDBGlobalSecondaryIndexHashKey 属性装饰 属性 有什么意义?

What is the point in decorating a property with the DynamoDBGlobalSecondaryIndexHashKey attribute?

有人可以向我解释 DynamoDBGlobalSecondaryIndexHashKey 的用途吗?

我只是在问,因为如果我使用特定的 GSI 查询我的 table,其中 C# 属性 已用此属性修饰,我仍然需要传递指定索引名称的 DynamoDBOperationConfig想要使用而不是从属性中获取它...

例如:

var operationConfig = new DynamoDBOperationConfig
{
   IndexName = "IndexName"
};

因此,我不确定用该属性装饰 属性 有什么意义。

我错过了什么?

指定查询使用哪个索引和指定组成索引的键是完全不同的两件事。

来自the docs

DynamoDBGlobalSecondaryIndexHashKey

Maps a class property to the partition key of a global secondary index. Use this attribute if you need to Query a global secondary index.

稍后,当您进行查询时,如果您想使用 GSI 而不是主要 table,您只需设置索引名称,映射器将使用这些注释获取键映射。

如果您没有在查询中指定 IndexName = "IndexName",那么映射器将假设您正在对 table 本身进行查询,而不是 索引(您可以在同一个 table 上同时拥有多个 GSI)。