Table of Contents

Class GlobalIndexKeyAttribute

Namespace
DynaSharp.Mapping
Assembly
DynaSharp.dll

Declares the keys of a global secondary index. The default attribute names come from the lowercase index name, so index GSI1 uses gsi1pk and gsi1sk. Index keys are computed on every full write.

[AttributeUsage(AttributeTargets.Class|AttributeTargets.Struct, AllowMultiple = true, Inherited = false)]
public sealed class GlobalIndexKeyAttribute : Attribute
Inheritance
GlobalIndexKeyAttribute
Inherited Members

Remarks

A template that is one bare placeholder, with an attribute name equal to that property's attribute, writes nothing extra: the property's own attribute is the index key, so a number stays an N key. An attribute shared with another key, as in an inverted index, is allowed when both use the same template.

A computed property feeds an index template only with ComputedFromAttribute: an update cannot know which stored properties a getter reads, so that attribute names them, and without it the index would go stale.

A timestamp is written in UTC: a DateTime of kind Local is converted, and one of kind Unspecified, which new DateTime(2026, 1, 15) and default have, names no instant, so the write throws KeyFormatException. Give it Utc, or use a DateOnly, which has no kind and is written as yyyy-MM-dd. A timestamp takes yyyy, yyyy-MM, yyyy-MM-dd, yyyy-MM-ddTHH, yyyy-MM-ddTHH:mm, s, ms, us or ticks. A bare {At} is ticks, seven fraction digits as in the attribute: it is the only lossless format, so a read can restore the property from the key. Every other format truncates, and {At:ms} is the one that matches keys the AWS SDK for .NET wrote.

Constructors

GlobalIndexKeyAttribute(string)

Initializes a new instance of the GlobalIndexKeyAttribute class.

public GlobalIndexKeyAttribute(string indexName)

Parameters

indexName string

The DynamoDB name of the index: 3 to 255 of a-z, A-Z, 0-9, _, - and ..

Properties

IndexName

Gets the DynamoDB name of the index.

public string IndexName { get; }

Property Value

string

PartitionKey

Gets or sets the key template of the index partition key. It is required.

public string? PartitionKey { get; set; }

Property Value

string

PartitionKeyAttributeName

Gets or sets the name of the attribute that holds the index partition key.

public string? PartitionKeyAttributeName { get; set; }

Property Value

string

SortKey

Gets or sets the key template of the index sort key, or null for an index without one.

public string? SortKey { get; set; }

Property Value

string

SortKeyAttributeName

Gets or sets the name of the attribute that holds the index sort key.

public string? SortKeyAttributeName { get; set; }

Property Value

string

Sparse

Gets or sets a value indicating whether items without a value leave the index. When any input of any template of the index is null, none of the index's key attributes is written, because one alone would be stored uselessly. Nullable inputs require this.

public bool Sparse { get; set; }

Property Value

bool

Remarks

An item is in an index only with both its keys. So on a sparse index an update that sets one key and does not produce the other throws InvalidOperationException when it is sent, naming the other key. On an index that is not sparse the same update writes the key it can compute and throws nothing: an item that exists keeps its other key, and an item the update creates stays out of the index. An update that can create an item sets every input of the index, ends in .IfExists(), or is a Put.