Database table API

Xperience stores most data in database tables. The API provides classes for managing the data of each table – an Info class, IInfoProvider interface (service), and an InfoProvider class.

Info object database table structure in Xperience

Info classes

Every Info class is related to a specific database table. Instances of Info classes represent entries (rows) in the given table – the class serves as a container for the data of the entry. The properties of an info class correspond to the columns of the related table.

Info class managers

The system offers the following options for CRUD operations over managed database objects. 

Generic provider class – IInfoProvider<TInfo>

You can manage objects via IInfoProvider<TInfo> instances. Substitute TInfo for the *Info class you want to work with. We recommend this approach for all custom objects added to the system. For example, to obtain an instance of a content language manager, use:

Initialize a generic info object provider via dependency injection

using CMS.DataEngine;

private readonly IInfoProvider<ContentLanguageInfo> contentLanguageProvider;

public MyClass(IInfoProvider<ContentLanguageInfo> contentLanguageProvider)
{
    this.contentLanguageProvider = contentLanguageProvider;
}

Note that not all system classes currently fully support this approach.  

The IInfoProvider<TInfo> and its associated extension methods provide conventional CRUD API in the form of Get, Set, and Delete methods. Support for asynchronous retrival ensures the GetAsync method. The Get methods expose multiple overloads for retrival via ID, GUID, or code name depending on the configuration of the corresponding object type. See Configure code generation for data classes for details about custom object type configuration.

For bulk operations, use the BulkInsert, BulkUpdate, and BulkDelete methods.

If you cannot use dependency injection in your codebase, you can instantiate the generic provider via the static CMS.DataEngine.Provider<TInfo>.Instance.

Dedicated provider classes

Each managed database object can have a dedicated provider class that ensures CRUD operations.

IInfoProvider interfaces

Most Info classes have a matching IInfoProvider interface (service), which allows basic management of the given objects – getting, creating, updating, and deleting – using the system’s ObjectQuery query syntax.

You can resolve instances of IInfoProvider services using dependency injection or via the Provider property of the corresponding Info class.

Code example

using CMS.Membership;

// ...

// Gets a UserInfo object representing the user with the "Andy" username
UserInfo user = UserInfo.Provider.Get("Andy");

// Saves the user's email address to a local variable
string userEmail = user.Email;

InfoProvider classes

InfoProvider classes are the actual implementations of the IInfoProvider interfaces. Every provider manages the data of a specific table using the related Info objects.

We do not recommend using InfoProvider classes directly for basic operations, such as getting, creating, or deleting objects. Use the corresponding IInfoProvider service instead.

However, InfoProvider classes often contain additional static business API methods that allow you to perform other operations related to the given object type.

Code example

using CMS.Membership;

// ...

// Gets a user's email
UserInfo user = UserInfo.Provider.Get("Andy");
string userEmail = user.Email;

// Checks if the user's email is unique
UserInfoProvider.IsEmailUnique(userEmail);