Let’s do a quick overview of the main features of XPO before we dive into details.

 

XPO (eXpress Persistent Objects) is a full-featured Object-Relational Mapping (ORM) framework developed by DevExpress. It is used to provide a mapping between the relational database tables and the objects used in a .NET application.

 

XPO allows developers to interact with a database in a more natural, object-oriented manner and eliminates the need to write complex SQL statements. It provides a high-level API for working with databases, automating common tasks such as connecting to a database, querying data, and committing changes.

 

With XPO, developers can focus on the business logic of the application rather than worrying about the low-level details of working with databases.

 

Throughout the book, we will explore each feature of XPO in depth, providing a comprehensive understanding of its capabilities. However, here are some of the most notable features of XPO that we will highlight:

 

  1. Object-Relational Mapping (ORM): XPO provides a mapping between the relational database tables and the objects used in a .NET application. This makes it easier for developers to interact with databases in a more natural, object-oriented manner.
  2. High-Level API: XPO provides a high-level API for working with databases, automating common tasks such as connecting to a database, querying data, and committing changes.
  3. Data Types Mapping: XPO automatically maps .NET data types to their corresponding SQL data types and vice versa, eliminating the need for manual data type conversion.
  4. LINQ Support: XPO includes built-in LINQ (Language Integrated Query) support, making it easier to write complex, fine-tuned queries.
  5. Customizable SQL Generation: XPO allows developers to customize the SQL generated by the framework, providing greater control over the database operations.
  6. Lazy Loading: XPO supports lazy loading, meaning that related objects can be loaded on demand, reducing the amount of data that needs to be loaded at once and improving performance.
  7. Change Tracking: XPO tracks changes made to objects and automatically updates the database as needed, eliminating the need to write manual update statements.
  8. Validation: XPO provides built-in support for validating objects, making it easier to enforce business rules and ensure data integrity.
  9. Caching: XPO provides caching capabilities, allowing frequently used data to be cached and reducing the number of database queries required.
  10. Support for Multiple Databases: XPO supports a wide range of relational databases, including SQL Server, Oracle, MySQL, PostgreSQL, and more.

 

Enhancing XPO with Metadata : Annotations

 

In C#, annotations are attributes that can be applied to classes, properties, methods, and other program elements to add metadata or configuration information.

 

In XPO, annotations are used extensively to configure the behavior of persistent classes.

 

XPO provides a number of built-in annotations that can be used to customize the behavior of persistent classes, making it easier to work with relational data using object-oriented programming techniques.

 

Some of the most commonly used annotations include:

 

  • Persistent: Specifies the name of the database table that the persistent class is mapped to.
  • PersistentAlias: Specifies the name of the database column that a property is mapped to.
  • Size: Specifies the maximum size of a database column that a property is mapped to.
  • Key: Marks a property as a key property for the persistent class.
  • NonPersistent: Marks a property as not persistent, meaning it is not mapped to a database column.
  • Association: Specifies the name of a database column that contains a foreign key for a one-to-many or many-to-many relationship.

 

In addition to the built-in annotations, XPO also provides a mechanism for defining custom annotations. You can define a custom annotation by defining a class that is inherited from the Attribute class.

 

Annotations can be applied using a variety of mechanisms, including directly in code, via configuration files, or through attributes on other annotations.

 

We will witness the practical implementation of annotations throughout the book, including our own custom annotations. However, we wanted to introduce them early on as they play a crucial role in the efficient mapping and management of data within XPO.

 

Now that we have refreshed our understanding of XPO’s main goal and features, let’s delve into the “O”, the “R”, and the “M” of an ORM.

And that’s all for this post, until next time ))

We are excited to announce that we are currently in the process of writing a comprehensive book about DevExpress XPO. As we work on this project, we believe it is essential to involve our readers and gather their valuable feedback. Therefore, we have decided to share articles from the book as we complete them, giving you an opportunity to provide input and suggestions that we can consider for inclusion in the final release. Keep in mind that the content presented is subject to change. We greatly appreciate your participation in this collaborative effort.

Related Articles

SOLID design pattern and XPO

What is an O.R.M (Object-Relational Mapping)

ADO The origin of data access in .NET

Relational database systems: the holy grail of data