Amazon DynamoDB · Types · Entities and values
ArxEntity
Definition
- Namespace
ARX.SDK.Services- Package
ARX.SDK
public class ArxEntityA record of one table: its name (EntityName), its attributes (column name to value) and, once written or read, its id (RecordId). Set a value with entity["name"] = "Contoso".
Constructor
ArxEntity()An entity with no table yet: set EntityName before using it.
ArxEntity(string entityName)An empty record of this table.
Parameter Type Description entityNamestringThe table, or schema.table.ArxEntity(string entityName, ArxAttributeCollection attributes)An entity with the given attribute collection: a provider reading rows passes one it built.
Parameter Type Description entityNamestringThe table, or schema.table.attributesArxAttributeCollectionThe attributes to use as they are (not copied). ArxEntity(string entityName, int attributeCapacity)An entity with room for
attributeCapacityattributes, so a provider that knows how many it reads (a result row) fills it without the dictionary growing.Parameter Type Description entityNamestringThe table, or schema.table.attributeCapacityintHow many attributes the entity will hold.
Properties
ArxRecordId? RecordId { get; set; }The record's id, of any declared id type: read it with
AsInt64(),AsString(),AsGuid()orValue. Set by Create and by every read that knows the table's id. Create reads the id to write from the attributes, never from this property, so an entity ARX created or read can be created again as a copy. An id your code sets here before a Create is refused (ARX1001) unless the id attribute holds the same id: to give a record its id, set the id attribute (entity["id"] = …).ArxIdColumn? IdColumn { get; set; }The id column for this entity, when no schema declares its table: a service with no schema catalog, and no schema passed to the call. With a schema, setting it is refused (ARX1001), because a table is declared in one place; to declare a table differently for one call, pass a schema to that call instead. Null (the default) means the schema's declaration is used.
NoIdColumnfor a table with no id.IReadOnlyList<ArxKey>? Keys { get; set; }The table's business keys for this entity, when no schema declares its table; with a schema, setting them is refused (ARX1001). Optional: null (the default) means the schema's keys, or none. Keys alone don't declare an id. Create doesn't use them; Update and Delete can find rows by them.
string EntityName { get; set; }The table (or
schema.table) the record belongs to.ArxAttributeCollection Attributes { get; set; }The record's values by column name. Create and Update write exactly these; a read fills them.
object? this[string attributeName] { get; set; }A column's value: null when the record has no such attribute. Setting it adds or replaces the attribute.
Methods
bool Contains(string attributeName)True when the entity has the attribute (names are matched ignoring case).
Parameter Type Description attributeNamestringThe attribute (column) name, matched ignoring case. T? GetAttributeValue<T>(string attributeName)The attribute's value as
T, or its default when the attribute is missing or null (soGetAttributeValue<int>of a NULL column is 0, andGetAttributeValue<int?>is null: ask for a nullable type to tell NULL from 0.Containsis true for a column that was read as NULL).Parameter Type Description attributeNamestringThe attribute (column) name, matched ignoring case. ArxEntityReference ToEntityReference(string? primaryColumnName = null)A reference to this entity's record, for a lookup on another entity. Its
Nameis the value ofprimaryColumnName(a lookup's own name when the column is one), or null when no column is named or the entity doesn't have it.Parameter Type Description primaryColumnNamestring?= nullThe column whose value names the record (a display name), or null.
Usage
A line from a verified sample; the full, runnable code is on its page.
var product = new ArxEntity("product");Create one record, in either design, scenario 1
Used in:
- Create one record, in either designCreate
- Catch the errors a create meetsCreate
- Store every kind of valueCreate
- Catch an injection attemptCreate
- Create in an ARX transactionCreate
- A security check around createsCreate
- Set up the service from DynamoDB's tablesCreate
- Set the service up for productionCreate
- Use attributes named outside the name rule, through aliasesCreate
- Log every call through ILoggerCreate
- Create many records in one callCreateMultiple
- Spread a hot partition with write shardingCreateMultiple
- Update one recordUpdate
- How an update finds its itemUpdate
- Catch an injection attemptUpdate
- Detect a change made since the readUpdate
- Update in a batch scopeUpdate
- Set up the service from DynamoDB's tablesUpdate
- Move an item to a new keyUpdate
- Update many records in one callUpdateMultiple
- Update or delete every item a filter matchesUpdateMultiple
- A security check around updatesUpdateMultiple
- Delete one recordDelete
- How a delete finds its itemsDelete
- Catch an injection attemptDelete
- Replace a record in a transactionDelete
- A security check around deletesDelete
- Set up the service from DynamoDB's tablesDelete
- Delete many records in one callDeleteMultiple
- Retrieve one recordRetrieve
- Set up the service from DynamoDB's tablesRetrieve
- Retrieve many recordsRetrieveMultiple
- Page through resultsRetrieveMultiple
- A customer and its orders in one requestRetrieveMultiple
- Orders by status, through an indexRetrieveMultiple
- Catch an injection attemptRetrieveMultiple
- Scan when you mustRetrieveMultiple
- A security check around searchesRetrieveMultiple
- Protect paging cookiesRetrieveMultiple
Notes
Reading values: entity["name"] is null both for a NULL column and for an attribute the record doesn't have (a column not read, or a mistyped name), so use Contains to tell them apart. Names are matched ignoring case, on read as on write (entity["Name"] finds name). GetAttributeValue{T} converts numbers when nothing is lost (ARX4001 when the number doesn't fit), reads a lookup or a record id as its id, and a UTC or Local DateTime as a DateTimeOffset (and back); any other mismatch is ARX4004. A declared lookup reads back as an ArxEntityReference. entity.Attributes["x"] is the dictionary underneath: it throws KeyNotFoundException for a missing attribute, where the indexer returns null.