5 min read
View Entities in Mendix

Mendix is constantly evolving. Updates are released monthly for the latest version of the development platform (Mendix 10). These updates are called minor releases and usually contain small improvements, but sometimes new features are introduced that can drastically improve application development. In the latest minor release, 10.19, which came out at the end of January, Mendix added one such important new feature: View Entities. This is a new type of entity that can be used to display or share data stored in the database of Mendix applications. At first this may not sound groundbreaking, but it will make the development of a number of common functions in Mendix considerably easier. In addition, using View Entities can improve application performance. In this blog you will read what View Entities are and in which scenarios they can be used.
Entities in Mendix
Entities in Mendix are part of an application's data model. They are essentially the tables in which data is stored. With the addition of View Entities, there are now four types of entities in Mendix:
- Persistent Entities
The data in this type of entity is stored in the application's database. - Non-persistent Entities
The data in this type of entity is volatile, i.e. the data is not stored in the database. The data is created during a user's session. - External Entities
The data in this type of entity is stored in another Mendix application. This type of entity can be used by connecting an application to Mendix Data Hub. - View Entities
The data in this type of entity is retrieved from other entities by means of OQL queries.
What are View Entities?
View Entities are a new type of entity added in Mendix 10.19. These entities are created using OQL queries. The queries describe searches that retrieve data from other entities. View entities can be used in most places in an application where persistent entities are currently used. A view entity can, for example, be connected to a data grid, and the view entity then behaves like a persistent entity with full support for filtering, pagination and sorting on top of the query. View entities are read-only. To change the data in view entities, the underlying data in the persistent entities must be changed.
Adding View Entities with OQL queries
When creating view entities in Mendix Studio Pro, you as a developer get help writing the queries. There is a new OQL editor that lets you write OQL queries with syntax checking. While you write the query, the editor suggests names of the entities and attributes from the application's data model. The OQL editor includes a handy preview that displays the result of the query.

What is OQL?
The Mendix Object Query Language (OQL) is a relational query language that closely resembles SQL. The big advantage of OQL is that when writing queries you use the names of entities instead of the actual table names in the database. Moreover, in OQL queries you can use predefined associations (relationships) between entities to link records in different tables without having to think about which key fields to use to join tables. Despite these differences, many SQL statements and keywords also work in OQL.
OQL version 2
OQL v2 was introduced in Mendix version 10.19. To be able to use View Entities in Mendix, you need to enable OQL v2 by changing an app setting in Mendix Studio Pro. The syntax of OQL v2 is essentially the same as OQL v1, but there are some differences in how a few specific functions are handled. When you switch to OQL v2, it is important to check whether existing OQL queries already used in the application still give the expected result. More information on this can be found in the Mendix documentation.
Use cases for View Entities
View Entities offer all kinds of possibilities that will save app developers a lot of time and enable performance improvements. Below are a number of examples of use cases where using View Entities is beneficial.
Adding dashboards with charts
A common function of Mendix applications is showing KPIs and charts on a dashboard page. With OQL queries you can write efficient searches that perform the calculations and aggregations needed for the charts and KPIs. View Entities give direct access to the results of OQL queries and are therefore very useful for building dashboards. Previously this was a lot harder, because the calculations and aggregations had to be performed with logic in microflows.
Publishing datasets via an API layer
If you want to publish data from a Mendix application via an API (for example as OData endpoints), it is wise to decouple the data model for the API from the data model created in the app for data storage. This can be achieved by adding View Entities to the application and then publishing the View Entities as API endpoints. That way you keep the flexibility to make changes to the data model for the API layer without having to change the "core" data model.
Speeding up overview pages
If you want to show data from several linked entities in a data grid, this can cause performance problems. Especially in applications with large datasets, opening overview pages can take (too) long. View Entities can help here, because retrieving data from the database is much faster with OQL queries. You also keep the flexibility in how the data is displayed, because sorting, paging and filtering remain possible when a View Entity is designated as the source in a data grid.
Public beta
Using View Entities in applications in production environments is currently not recommended, because the feature was released with the status 'public beta'. It is therefore possible that the functionality will be changed and/or improved in the coming minor releases. On the other hand, it is interesting to explore how View Entities work now and to gain experience with applying OQL v2.
Want to stay up to date?
Want to know more about Mendix? Sign up for our newsletter and stay up to date every month with all our new blogs. You can sign up via the button below.

Written by

Steven Samuels Brusse