Table of Contents

Class ComputedFromAttribute

Namespace
DynaSharp.Mapping
Assembly
DynaSharp.dll

Names the stored properties a computed property is derived from, so that it can feed a key template of an index. A getter is code the generator cannot read, so this is the promise it goes by: the getter reads what is named here and nothing else that an update can change.

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

Examples

[DynamoDbEntity]
[Discriminator("VISIT")]
[PartitionKey("STORE#{StoreId}")]
[SortKey("AT#{Arrival}")]
[GlobalIndexKey("ByDay", PartitionKey = "DAY#{ArrivalDay}", SortKey = "{Arrival}")]
public partial record StoreCheckin
{
    public required string StoreId { get; init; }

    public required DateTimeOffset Arrival { get; init; }

    [ComputedFrom(nameof(Arrival))]
    public DateOnly ArrivalDay => DateOnly.FromDateTime(Arrival.UtcDateTime);
}

Remarks

A Put, Item.From and a batch run the getter, so the key is right. An update has no instance to run it on, which is why an index template takes a computed property only with this attribute: a write by handle to a named property, also to a path inside it such as Attrs.Message.At(Msg.Attrs.Arrival), throws InvalidOperationException when the update ends, and so does a write by handle to a computed property with an attribute of its own, where the key would follow the update and not the getter, and an update of another input of the same template, because the key cannot follow either way. Use a Put of the changed entity. SetIfNotNull of null writes nothing and stays legal.

A raw path is not checked, as everywhere: .Set("message", value) goes out, and the index keeps the key it had. On a key of the table this attribute adds the same check, and there DynamoDB cannot update the key anyway.

Each name is a property of the same type with an attribute of its own: not computed, not DynamoDbIgnoreAttribute and not KeyOnlyAttribute, and not the VersionAttribute, which every write moves without a handle. One level only, and a named property may feed another key. The build reports what breaks this as DYNA119, and a write that will throw as DYNA219.

Constructors

ComputedFromAttribute(params string[])

Names the stored properties a computed property is derived from, so that it can feed a key template of an index. A getter is code the generator cannot read, so this is the promise it goes by: the getter reads what is named here and nothing else that an update can change.

public ComputedFromAttribute(params string[] properties)

Parameters

properties string[]

The names of the properties, for which nameof is the way to write them.

Examples

[DynamoDbEntity]
[Discriminator("VISIT")]
[PartitionKey("STORE#{StoreId}")]
[SortKey("AT#{Arrival}")]
[GlobalIndexKey("ByDay", PartitionKey = "DAY#{ArrivalDay}", SortKey = "{Arrival}")]
public partial record StoreCheckin
{
    public required string StoreId { get; init; }

    public required DateTimeOffset Arrival { get; init; }

    [ComputedFrom(nameof(Arrival))]
    public DateOnly ArrivalDay => DateOnly.FromDateTime(Arrival.UtcDateTime);
}

Remarks

A Put, Item.From and a batch run the getter, so the key is right. An update has no instance to run it on, which is why an index template takes a computed property only with this attribute: a write by handle to a named property, also to a path inside it such as Attrs.Message.At(Msg.Attrs.Arrival), throws InvalidOperationException when the update ends, and so does a write by handle to a computed property with an attribute of its own, where the key would follow the update and not the getter, and an update of another input of the same template, because the key cannot follow either way. Use a Put of the changed entity. SetIfNotNull of null writes nothing and stays legal.

A raw path is not checked, as everywhere: .Set("message", value) goes out, and the index keeps the key it had. On a key of the table this attribute adds the same check, and there DynamoDB cannot update the key anyway.

Each name is a property of the same type with an attribute of its own: not computed, not DynamoDbIgnoreAttribute and not KeyOnlyAttribute, and not the VersionAttribute, which every write moves without a handle. One level only, and a named property may feed another key. The build reports what breaks this as DYNA119, and a write that will throw as DYNA219.

Properties

Properties

Gets the names of the properties.

public IReadOnlyList<string> Properties { get; }

Property Value

IReadOnlyList<string>