Table of Contents

Class DiscriminatorAttribute

Namespace
DynaSharp.Mapping
Assembly
DynaSharp.dll

Sets the discriminator of an entity: the value stored in each of its items, in an attribute named _type, that tells which entity an item is, so that several entities can share a table and a typed read gets its own items. It is required on every entity, as [Discriminator("ORDER")].

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

Remarks

Required. A default of the type name would turn renaming a class into a silent migration. DiscriminatorOptOut opts out for the entities of an assembly that do not have it.

Reads. Typed reads check the attribute and fail with a mapping exception naming the type they found, because a query over an overloaded prefix can return other types. Typed queries and scans filter on it. For a table written by other tools, which has no such attribute, set OptOut instead of a value: the type then takes no part in mixed queries. An item has no order of attributes, so an attribute the two types share with values of different shapes can fail first, under its own name.

Constructors

DiscriminatorAttribute()

Initializes a new instance of the DiscriminatorAttribute class, which opts out with OptOut.

public DiscriminatorAttribute()

DiscriminatorAttribute(string)

Initializes a new instance of the DiscriminatorAttribute class.

public DiscriminatorAttribute(string value)

Parameters

value string

The value stored in every item of the type. It cannot be empty.

Properties

AttributeName

Gets or sets the name of the attribute that holds the value. The default is _type.

public string? AttributeName { get; set; }

Property Value

string

OptOut

Gets or sets a value indicating whether the type has no discriminator at all, for a table written by other tools: nothing writes _type, a query or a scan does not filter on it, and the type takes no part in mixed reads. [assembly: DynamoDbDefaults(DiscriminatorOptOut = true)], DiscriminatorOptOut, says the same once for every entity of an assembly that has no DiscriminatorAttribute.

public bool OptOut { get; set; }

Property Value

bool

Value

Gets the value stored in every item of the type, or null after opting out.

public string? Value { get; }

Property Value

string