MongoDB · Types · Entities and values

ArxEntity

Definition

Namespace
ARX.SDK.Services
Package
ARX.SDK
C#
public class ArxEntity

A 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 attributeCapacity attributes, 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() or Value. 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. NoIdColumn for 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 (so GetAttributeValue<int> of a NULL column is 0, and GetAttributeValue<int?> is null: ask for a nullable type to tell NULL from 0. Contains is 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 Name is the value of primaryColumnName (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

C#

A line from a verified sample; the full, runnable code is on its page.

var entity = new ArxEntity("account");

Create one record and get its id, scenario 1

Used in:

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.