Create a Data Entity in D365

Thoughtware Article Published: Mar 02, 2018
Computer screen with code

A data entity represents a meaningful set of data in Dynamics 365 for Operations. For instance, a data entity could be created for a customer that contains information from various database tables that define what a customer is, e.g., name, payment information, addresses, etc. A data entity organizes all this data in a way that’s convenient to handle and allows users to work with the entity itself to import or export data, rather than having to import or export individual tables.

Let’s create a data entity to handle exporting and importing item serial numbers using single database InventSerial.

Create a D365 project in Visual Studio named DataEntityExample. To create a new entity, right-click the project and then click Add > New item. The Add New Item dialogue box opens.

Select Data Entity, and then set the Name property to ItemSerialNumber. Then click the Add button.

Data Entity in D365 - Example 1

Create a Data Entity in D365 1

In the Data Entity Wizard, all of the properties will be defaulted except Primary datasource. Select InventSerial table as the primary datasource to export/import the item serial numbers.

Click the Next button.

Data Entity in D365 - Example 2

Add fields to the new entity from the data source InventSerial as shown in the following screenshot. Click the Convert labels to field names checkbox to generate names from the existing labels. Note that the fields InventSerialId and ItemId are marked as mandatory and these fields will be used as the natural key for the entity.

Data Entity in D365 - Example 3

Click Finish. The newly created data entity and staging table are added to the project.

Data Entity in D365 - Example 4

In Solution Explorer, right-click on the ItemSerialNumber data entity node and then click Open. Set the Label property to Item Serial Numbers. This is the name that will get displayed in the data entity list.

To make the entity available in data management, the property Data Management Enabled should be set to Yes and the property Data Management Staging Table should be ItemSerialNumberStaging.

To make the entity available in an Odata scenario, the Public Collection Name and Public Entity Name will get defaulted, and the property Is Public should be set to Yes.

Data Entity in D365 - Example 5

Now open the ItemSerialNumberStaging table in the designer. Staging tables are used in import/export scenarios to temporarily store the data being exported and imported. In many cases, staging tables are mapped 1:1 to an entity. Note that the first four fields (DefinitionGroup, ExecutionId, IsSelected and TransferStatus) are the standard fields of a data entity staging table. The table also contains the data fields we selected while creating the data entity. Note that the data entity relations will be created automatically.

Data Entity in D365 - Example 6

In Solution Explorer, right-click the project, and then click Properties. Set Synchronize database on build property to True.

Note:  Entities are created as views in Microsoft SQL Server, and staging tables also are added. Therefore, we must sync a database when we build entities.

Now build the project by going to the Visual Studio toolbar and clicking Build > Build Solution.

Verify the build doesn't contain errors.

We’ve created a custom data entity!

Related Thoughtware

Kate & Ben — How can we help you? Contact Us!

How can we help you?