Table of Contents

Class DynamoDbDefaultsAttribute

Namespace
DynaSharp.Mapping
Assembly
DynaSharp.dll

Says once what a project would otherwise repeat on every mapped type: [assembly: DynamoDbDefaults(Naming = AttributeNaming.CamelCase, DiscriminatorOptOut = true, OmitEmpty = true)]. It holds for the entities and documents that the assembly declares, nested ones too, and it does not reach a type of another assembly, which has the defaults it was built with.

[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)]
public sealed class DynamoDbDefaultsAttribute : Attribute
Inheritance
DynamoDbDefaultsAttribute
Inherited Members

Remarks

The attribute is read at compile time, for every mapped type, and an analyzer that meets a type from metadata reads the defaults of the assembly of that type. A base type in another assembly counts as part of the type that is mapped: its properties take the defaults of the assembly of that type.

Constructors

DynamoDbDefaultsAttribute()

public DynamoDbDefaultsAttribute()

Properties

DiscriminatorOptOut

Gets or sets a value indicating whether an entity without DiscriminatorAttribute behaves as if it had [Discriminator(OptOut = true)], OptOut, for a service whose tables other tools write, and DYNA020 stays away. A [Discriminator("X")] on a type still wins.

public bool DiscriminatorOptOut { get; set; }

Property Value

bool

Naming

Gets or sets how the attribute of a property derives from its name, on entities and on documents. The default is AsDeclared.

public AttributeNaming Naming { get; set; }

Property Value

AttributeNaming

Remarks

Changing the naming renames stored attributes. Items written before stay as they are, under the old names, and a read skips those and takes the new names for missing: a property keeps its initial value without any error, and a required one throws. For a table that holds data, either migrate the items, or stay on the old naming and pin what differs with DynamoDbAttributeAttribute.

Renaming a property does the same. The attribute follows the name of the property under every naming, AsDeclared too, so a rename refactoring compiles and renames a stored attribute. A property whose name may change takes DynamoDbAttributeAttribute.

It goes for every attribute that takes its name from a property, and that includes a plain key: [PartitionKey] public string UserId is the attribute user_id under SnakeCase. A table cannot rename a key, so an existing table takes an explicit AttributeName or DynamoDbAttributeAttribute, which win over this. So does a template of one bare placeholder: it is the attribute of its property only if its AttributeName is the converted name.

It does not touch a name that derives from no property: pk, sk, <index>pk, <index>sk and _type are frozen, whatever the naming. Two properties that end up with one name are DYNA004, as they would be with one DynamoDbAttributeAttribute.

OmitEmpty

Gets or sets a value indicating whether every string, list, set, dictionary and array behaves as if it had OmitEmptyAttribute. A property that feeds a key is always written, and so is one that a read cannot do without, as OmitEmptyAttribute says. An empty list then reads back as null or as the initial value, and [OmitEmpty(false)] takes it back for a property or a type.

public bool OmitEmpty { get; set; }

Property Value

bool

Table

Gets or sets the table of every entity of the assembly that declares none with Table, for a service whose entities share one table.

public string? Table { get; set; }

Property Value

string

Remarks

The entity wins. [DynamoDbEntity(Table = "sessions")] puts one entity into a table of its own, and an explicit name of Table<T>(string) wins over both.

The rules are those of the entity. The name is checked as Table says, and the entities that end up in the table must agree on the names of their keys.