Skip to main content

6 min read

View Entities in Mendix

View Entities in Mendix

Mendix is constantly evolving. Updates are released every month 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 newest minor release, 10.19, released at the end of January, Mendix added just such an 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. This might not sound especially groundbreaking at first, but it will substantially simplify the development of a number of common features in Mendix. In addition, using View Entities can improve application performance. In this blog, you'll 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're essentially the tables in which data is stored. With the addition of View Entities, there are now four types of entities in Mendix:

  1. Persistent Entities
    The data in this type of entity is stored in the application's database.
  2. Non-persistent Entities
    The data in this type of entity is transient, meaning the data isn't stored in the database. The data is created during a user's session.
  3. 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.
  4. View Entities
    The data in this type of entity is retrieved from other entities using 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 search operations used to 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 only suitable for reading data. 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're helped as a developer with writing the queries (the search operations). There's a new OQL editor with which you can write OQL queries with syntax checking. As you write the query, the editor suggests names of entities and attributes from the application's data model. The OQL editor includes a handy preview that shows the result of the query.

OQL editor in Mendix 10.19

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. In addition, OQL queries let you 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 instructions and keywords from the SQL language 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, it's necessary 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's important to check whether existing OQL queries already used in the application still produce the expected result. More information on this can be found in Mendix's documentation.

Use cases for View Entities

View Entities offer all kinds of possibilities that will save app developers a lot of time and can help achieve performance improvements. Below are a few examples of use cases where using View Entities offers advantages.

Adding dashboards with charts
A common feature of Mendix applications is displaying KPIs and charts on a dashboard page. With OQL queries, you can write efficient queries that perform the calculations and aggregations needed for the charts and KPIs. View Entities provide direct access to the results of OQL queries and are therefore very handy for building dashboards. Previously, this was a lot more difficult, because the calculations and aggregations had to be performed using logic in microflows.

Publishing datasets via an API layer
When you want to publish data from a Mendix application via an API (for example, as OData endpoints), it's 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. This way, you retain the flexibility to make changes to the data model for the API layer without having to modify the “core” data model.

Speeding up overview pages
When you want to display data from multiple linked entities in a data grid, this can cause performance issues. Especially with applications that have large datasets, opening overview pages can then take (too) long. View Entities can offer a solution here, because retrieving data from the database is much faster with OQL queries. In addition, you retain flexibility in displaying the data, since sorting, browsing, and filtering remain possible when a View Entity is designated as the source in a data grid.

Public beta

Using View Entities in applications on production environments is currently still discouraged, because the feature was released with ‘public beta’ status. It's therefore not impossible that the functionality will be adjusted and/or improved in upcoming minor releases. On the other hand, it is interesting to already explore how View Entities work and to gain experience applying OQL v2 in the meantime.

Want to stay up to date?

Want to know more about Mendix? Then sign up for our newsletter, so you'll be up to date with all our new blogs every month. You can sign up via the button below.

Sign up for the newsletter

Written by Steven Samuels Brusse,
Senior Consultant