MSBA-342 · Lesson 1 of 12 · 23 min
Data entities
▶ Video coming soon A video version of this lesson is on the way.
A week after the inspection certificate design was signed off, Desmond Oyediran-Platt pinned a new page to the clinic channel. It was called the integration register, and it listed every system that would have to exchange data with Dynamics 365 Finance and Supply Chain Management at Cobalt Ridge Manufacturing once the company went live in 2027. There were eight rows. The plant scheduling tool at Hamilton still received a nightly file of open orders. The plant quality system needed to hear about every inspection certificate recorded on a casting purchase line. Prairieline Pump Supply, the largest distributor, wanted to register pump warranties from its own portal. Two carriers sent freight invoice lines. The finance team wanted analytics in Microsoft Fabric. A field technician app was on the wish list, and at the bottom, in a row Desmond had shaded in grey, sat a proposal from Henrik Salo for a fleet of warehouse robots at the Calgary distribution warehouse.
Prudence Okolo, the partner's junior developer, had finished the first two clinic series with Desmond. She could now build tables, forms, classes, extensions, batch jobs and reports in X++. This third series, which Desmond called the integration clinics, would teach her how all of that work meets the outside world: through data entities, OData, custom services, recurring integrations, business events, dual-write, virtual entities, Electronic reporting, analytics, the Power Platform and the performance rules that keep integrations from hurting the people who use the system every day. The series is undated; it ran in the second half of November, and anything that happens after go-live is described here as a plan. The first clinic started where almost every integration in finance and operations apps starts: with the data entity.
What a data entity is
A data entity is an abstraction over one or more tables that presents a business concept in a shape that people and programs can understand. A customer in the database is spread across a dozen tables: the customer record, the party record, postal addresses, electronic addresses, financial dimensions and more. The customer data entity flattens those into one row with columns such as customer account, name, group, currency, address and phone. A program that wants to create a customer does not need to know how the normalized tables relate; it sends one row to the entity and the entity writes the right records in the right order.
Technically, a data entity is a metadata element in the Application Object Tree. It has a primary data source (a table), zero or more joined data sources, a set of fields mapped to fields of those data sources, a key, and methods that run when records are read or written. When the database is synchronized, the entity becomes a SQL view, which is why reading from an entity costs about the same as reading from a well-written query. Writing through the entity does not write to the view; instead the entity runs its own logic and inserts or updates the backing tables, calling their insert, update, validateWrite and validateField methods along the way. That detail matters: business rules on the tables still run when data arrives through an entity.
Data entities replaced the many separate import and export mechanisms of earlier product versions. The same entity can serve several purposes at once: it can be used by the data management framework for file imports and exports, by OData for synchronous web requests, by virtual entities in Dataverse, by dual-write, by Excel and by the analytics features. Microsoft ships thousands of entities with the application. A developer's first job is therefore to look for a standard entity that already does what the integration needs, and only build a new one when nothing fits.
Entity categories and properties
Every entity has a category that describes the kind of data it carries. The category does not change behaviour much, but it guides how data projects order their work and how people understand the entity. The table lists the categories with an example from the Cobalt Ridge register.
| Category | What it holds | Cobalt Ridge example |
|---|---|---|
| Parameter | Setup values that usually have one record per company | Warranty parameters (default months per product family) |
| Reference | Simple code lists used by other data | Warranty statuses, carrier codes |
| Master | Business objects that change slowly | Customers, released products, pump warranties |
| Document | Header and lines that work together | Sales orders, purchase orders, freight invoices |
| Transaction | Posted or historical records | Posted inspection certificates, inventory transactions |
The properties of an entity decide where it can be used. Public marks the entity as available to OData, and Public entity name and Public collection name set the names that appear in web requests, usually a singular and a plural. Data management enabled makes the entity available in import and export projects, and Data management staging table names the staging table the framework uses. Is read only blocks writes. Primary key is set to the entity key, a set of fields that uniquely identifies a row in business terms, such as a customer account, rather than the internal RecId. Allow row version change tracking lets Dataverse and the analytics features detect changed rows, a property that comes back in lesson 9. Enable set based SQL operations lets the framework write many rows with set-based statements when no row-level logic stands in the way, which matters for performance in lesson 11.
Entity keys deserve a moment. Because integrations happen between systems that do not share internal record identifiers, the entity key must be a natural key that the other system knows. For the pump warranty entity, Desmond chose the serial number, which is already unique by the SerialIdx index Prudence built in the fundamentals course. For a company-specific entity, the legal entity identifier, the data area, is added to the key automatically, so the same serial number could in principle exist in CRCA and CRUS without a clash.
Building the pump warranty entity
The first real integration on the register was the distributor warranty feed. Prairieline Pump Supply sells pumps from stock and wanted to register the installation date and customer of each pump the day the installer finishes, rather than mailing a form. That needed an entity over the warranty table that Prudence had built in October. Desmond asked her to create it with the Data entity wizard in Visual Studio, which is the usual way to start: right-click the project, add a new item, choose Data entity, select the primary data source, and let the wizard propose fields, a staging table and a privilege pair.
The wizard produced a sensible first draft. Prudence then cleaned it up. She renamed the fields to read well in a web request, removed the RecId-based relation fields the wizard had proposed, added the customer name and product name through joined read-only data sources so that a portal could show them without a second request, and set the key to the serial number. She set the category to Master, turned on Public with the names CRPumpWarranty and CRPumpWarranties, turned on Data management enabled, and kept the generated staging table CRPumpWarrantyStaging.
Data entity CRPumpWarrantyEntity (model CobaltRidgeCustom)
Label @CRCustom:PumpWarranties
Entity category Master
Public Yes
Public entity name CRPumpWarranty
Public collection name CRPumpWarranties
Data management enabled Yes
Staging table CRPumpWarrantyStaging
Primary key EntityKey (SerialNumber)
Data sources
CRPumpWarrantyTable (root)
CustTable (outer join, read only) -> DirPartyTable for CustomerName
InventTable (outer join, read only) -> product name
Fields
SerialNumber, ItemId, CustomerAccount, CustomerName, ProductName,
InstallDate, WarrantyMonths, Status, EndDate (read only)
Security privileges
CRPumpWarrantyEntityView, CRPumpWarrantyEntityMaintainTwo fields needed thought. The end date is calculated by the warranty calculator class whenever the install date or the number of months changes, so the entity marks it read only: an outside system should never send an end date, because the calculation belongs to Cobalt Ridge. The status is an enum. In a web request, enums appear as their symbol names, such as Active or Void, rather than numbers, which makes the feed readable and safe if the enum gains values later.
Methods that shape the data
Data entities have their own methods, and a developer overrides them to adjust how data flows. The most common are listed below. Most of them follow the same pattern as table methods, with one extra layer: the entity decides how a single entity row turns into records in each data source.
| Method | When it runs | Typical use |
|---|---|---|
| initValue | When a new entity record is created | Default values for fields the caller did not send |
| validateWrite / validateField | Before a write | Business checks that apply only to data arriving through the entity |
| mapEntityToDataSource | For each data source during a write | Set fields on a data source that do not map directly |
| initializeEntityDataSource | Before a data source record is written | Find an existing related record instead of creating one |
| insertEntityDataSource / updateEntityDataSource | When each data source is written | Change the order or skip a data source |
| postLoad | After a row is read | Fill virtual fields that are calculated in X++ |
| persistEntity | Around the whole write | Rarely overridden; wraps the full insert or update |
Desmond's rule of thumb was to put business rules on the table, where every path into the data will run them, and to put rules on the entity only when they are specific to integration. The warranty feed had one such rule. A distributor must not register a warranty for a pump that Cobalt Ridge has never sold to that distributor, because the warranty is a promise to the end customer that runs through the sale. A person keying a warranty in the form could override that check after a phone call; a portal could not. So the check went on the entity's validateWrite method.
public boolean validateWrite()
{
boolean ret = super();
// Integration-only rule: the serial number must have been shipped
// to the distributor sending the registration.
if (ret && !CRPumpWarrantyService::serialShippedToCustomer(
this.SerialNumber, this.CustomerAccount))
{
ret = checkFailed(strFmt("@CRCustom:SerialNotShippedToCustomer",
this.SerialNumber, this.CustomerAccount));
}
return ret;
}Some fields are not stored anywhere but still belong in an entity. There are two ways to provide them. A computed column is defined by a static method that returns a SQL expression; it becomes part of the view, so it is calculated by the database, can be filtered and sorted, and is cheap to read in bulk. A virtual field is filled by X++ in the postLoad method, after the row is read; it can use any X++ logic but is calculated one row at a time and cannot be used in a filter. Prudence wanted a field showing how many days of warranty were left. Desmond suggested a computed column using the SQL date difference between today and the end date, because the distributor portal would want to sort by it.
The data management framework
The data management framework, often shortened to DMF and still called DIXF in some older documents, is the engine that moves files and packages through entities. It appears in the Data management workspace, where people create import and export projects. A project lists one or more entities, the source format of each (comma-separated values, Excel, XML or a package), the mapping between the source columns and the staging columns, and the order in which entities are processed. When a project runs, data travels in two steps. First the file is loaded into the staging table, where every row can be checked and corrected. Then the staging rows are copied to the target through the entity, which runs the entity's logic and the tables' validation.
Staging is what makes the framework safe for large loads. If one row in ten thousand fails validation, the other rows can still be written, and the failed row stays in staging with its error message, ready to be fixed and rerun. The project's execution history shows each run, the number of records created, updated and in error, and links to the staging data. For the warranty entity, Desmond had Prudence export the twelve test warranties from the CONFIG sandbox to Excel, change two install dates, and import the file again, then look at the execution details to see the update count rather than a create count. The key on the serial number is what made the second import an update.
A data package is a zip file that holds one or more entity files together with a manifest that describes them and the order to process them. Packages are how consultants move configuration between environments, and how programs exchange several entities in one go. Packages also matter to developers because the package REST API, covered in lesson 4, imports and exports whole packages from another program. Microsoft also publishes ready-made configuration packages for common setups, and Annelise Vorster-Kim had used several of them when she built the CONFIG sandbox.
Security for entities
An entity is a door into the data, so it needs its own lock. When the wizard creates an entity, it also creates a view privilege and a maintain privilege for it. Those privileges control who can read or write through OData, Excel and the data management workspace. For people who use the data management workspace, there is an extra layer: the Data management administrator role and similar roles decide who can run projects at all. For programs, the privileges are granted through the security role assigned to the integration user that the program signs in as, which lesson 2 covers in detail.
Desmond insisted on one more habit. Every entity on the register had an owner in the business who agreed which fields went out and which came in, and that owner signed off on the field list in the decision log. For the warranty entity the owner was Annelise, with Thandeka Morrow, the controller, checking that no financial fields were exposed. It took ten minutes and avoided the common problem of entities that quietly expose more data than anyone intended.
Worked problem
Choosing between a standard and a custom entity
The integration register lists three needs: (1) Prairieline registers pump warranties from its portal; (2) the carriers send freight invoice lines; (3) the plant scheduling tool needs open sales order lines every night. For each, should Prudence look for a standard entity or build a custom one?
Show solution
- Warranties live in a custom table that Microsoft has never heard of, so no standard entity exists. A custom entity, CRPumpWarrantyEntity, is the only choice.
- Freight invoices are part of standard transportation management, so the first step is to search Application Explorer and the Data management workspace for a standard freight invoice entity and check whether its fields match what the carriers send.
- Sales order lines have standard entities. The scheduling tool needs a few extra fields, such as the pump configuration, so the right move is to use the standard entity and add fields through an entity extension rather than copying it.
- In every case, check the key: the outside system must know the values in it.
Answer: One custom entity (warranties), one standard entity to verify (freight invoices), and one standard entity extended with a few fields (sales order lines). Building custom entities is the last resort, not the first.
How the first clinic ended
By the end of the first clinic, the warranty entity was built, deployed to Prudence's unified developer environment, visible in the Data management workspace and round-tripped through Excel. Desmond added a column to the integration register called entity and filled it in for each row. Six of the eight rows already had an answer. The robot row was still grey.
- Look for a standard entity first; extend it before you copy it.
- Choose a natural key that the other system knows.
- Put universal rules on tables and integration-only rules on the entity.
- Mark calculated fields read only and prefer computed columns for fields people will filter on.
- Give every entity an owner who signs off the field list.
Common mistakes
MistakeUsing RecId values as the key that an outside system sends.
InsteadUse a natural key such as a serial number or customer account; RecId values mean nothing outside the database.
MistakeCopying a standard entity to add two fields.
InsteadCreate an entity extension in your own model and add the fields there.
MistakeLetting an outside system write a field that Cobalt Ridge calculates.
InsteadMark calculated fields read only on the entity so the calculation stays in one place.
MistakeUsing a virtual field for a value people will filter or sort on.
InsteadUse a computed column, which is part of the SQL view and can be filtered.
Summary and key terms
- A data entity presents a business concept over one or more tables and becomes a SQL view at synchronization.
- Writes through an entity run the entity logic and the validation on the backing tables.
- Entity properties decide whether the entity is public for OData, enabled for data management, read only and change tracked.
- The data management framework loads files into staging, then copies to the target through the entity, keeping errors for correction.
- Entities need their own privileges and a business owner who signs off what they expose.
- Data entity
- An abstraction over one or more tables that presents a business concept for integration, import, export and analytics.
- Entity key
- The natural key of a data entity, used by outside systems to identify a row.
- Staging table
- A table where the data management framework holds imported rows before copying them to the target.
- Data management framework
- The engine behind import and export projects that moves files and packages through data entities.
- Data package
- A zip file containing entity files and a manifest, used to move several entities together.
- Computed column
- An entity field defined by a SQL expression that is calculated in the view.
- Virtual field
- An entity field filled by X++ code after a row is read.
Practice problems
Work each problem on paper first, then reveal the answer to check.
Why does a write through a data entity still run the validateWrite method of the backing table?
Show answer
Because the entity writes to the tables through their normal insert and update logic, so table validation runs on every path into the data.
What makes a second import of the same warranty file an update instead of a create?
Show answer
The entity key on the serial number: the framework finds an existing record with the same key and updates it.
When would you choose a virtual field over a computed column?
Show answer
When the value needs X++ logic that SQL cannot express and nobody needs to filter or sort on it.
Lesson quiz · 5 questions
Score 60% or more to complete this lesson.
Create a free account to save your progress, take quizzes and earn a certificate.