ZuloOne
English
Sign in
Menu

Create a data entity

Updated

A data entity is a public OData resource: a projection of a dictionary or a document on /odata/{PublicCollectionName} with $metadata, $filter, $select, and CRUD. It is not a web service (POST /api/rest/{Name}).

Note

From a script, use GetService<IDataEntityManager>(). Do not go to the source table with IDataService when you need the projection: the manager runs mapping, MapFromSource / MapToSource, write hooks, and the source RLS.

How to#

Files in DataEntities/<Name>/. The studio path is Developer → Scripting → Data entities.

  1. PascalCase name. The collection name defaults to the name.
  2. Exactly one primary source (a dictionary or a document).
  3. Fields map to a column, or IsComputed. The key is IsKey (usually MetaId).
  4. Turn on RequireExplicitRoles when an empty matrix must not be public over HTTP.
  5. Bump modelVersion (minor — new object).

Outside: token from the login host, then GET {PublicUrl}/odata/{Collection}?$filter=ID eq 'C-100'. The email in the token must be an active MetaUser. Source-table RLS still applies.

From a script:

var de = context.GetService<IDataEntityManager>();
var rows = await de.QueryAsync("CustomersV2", filter: "ID eq 'C-100'", select: "ID,Name", top: 20);

Call by collection name from a foreign event or service. Typed QueryAsync<CustomersV2>(…) is for when the POCO is in scope (the entity's own handler).

Tip

A computed field in $filter is 400. Writing a read-only entity is 405. A disabled entity is 404. RequireExplicitRoles gates HTTP /odata only — a script does not need that grant. Do not insert through the manager into the same table whose OnAfterInsert is currently running.

The longer page — mapping, events, rights — is Data Entity.

What's not there yet#

A data entity is not a place to hide business rules that belong on the source object. The source's events still run.

Where next#

Was this page helpful?