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 withIDataServicewhen 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.
- PascalCase name. The collection name defaults to the name.
- Exactly one primary source (a dictionary or a document).
- Fields map to a column, or
IsComputed. The key isIsKey(usuallyMetaId). - Turn on
RequireExplicitRoleswhen an empty matrix must not be public over HTTP. - 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
$filteris 400. Writing a read-only entity is 405. A disabled entity is 404.RequireExplicitRolesgates HTTP/odataonly — a script does not need that grant. Do not insert through the manager into the same table whoseOnAfterInsertis 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.