API reference

Attributes

The attributes used to map entities, relationships, stored procedures, auditing and repositories.

ORM Current 2 min read Updated

Entities and relationships#

Attribute On Purpose
[DbContextObject("group")] class Puts the entity (or stored procedure) in a named group, so AddDbObjects("group") in your context registers it
[TableInfo("table")] class The table the entity maps to; may be schema-qualified
[ColumnInfo("column", ...)] property Maps a column. Settings include IsPrimaryKey and IsAutoIncrement, and the generator also records type and default
[ForeignKey("table", "column")] property Declares the referenced table and column
[ColumnReference(nameof(Fk))] EntityRef<T> property Links a navigation to its foreign-key property

Navigation types are EntityRef<T> (one) and EntityList<T> (many). Entities inherit Entity<T> and implement properties with SetAndNotify(ref field, value).

Stored procedures#

Attribute On Purpose
[StoredProcInfo("name")] class Marks the class as a stored procedure and names it
[ParamInfo("name", ParamDirection = ...)] property Maps a parameter. Direction is Input by default, or Output, InputOutput, ReturnValue from System.Data.ParameterDirection

Result-set row classes use [ColumnInfo] on their properties.

Auditing#

The attributes are part of the free Abstractions assembly. The ready-made adapters that store the audit trail are Commercial, and you can write your own adapter against the free hooks. See Audit data access.

Attribute On Purpose
[Auditable(AuditType = ...)] class Audits the entity. AuditType flags: None, Insert, Update, Delete, All (default)
[Sensitive] property Redacts the column's old and new values (as ***REDACTED***) before they reach any audit adapter. The column name and the fact that it changed are still recorded

Repositories (Commercial)#

Attribute On Purpose
[KiwiRepositoryImplementation] class Supplies a custom implementation of a repository interface. Needs a public parameterless constructor

Source generator#

The generator package offers [GenerateEntity], [Column], [NavList], [NavRef], [RefKey] and [NotMapped] so you can declare fields and have the entity properties generated.