Retrieve related data for collection of items

With the Related data API, you can optimize performance when retrieving related data items for a specific collection of items. You do this by setting this collection to the context and thus, after the first related item is requested, Sitefinity CMS loads all the related data items per property for this collection. After this initial request, each time there is an additional request from the API for the related data items, Sitefinity CMS returns the results for the items from the context and not from the provider using the following method:
void SetRelatedDataSourceContext(this IEnumerable<IDataItem> items).

To do this, use the following template:

In the following example, you have a content type Sessions and you want to retrieve all Speaker related data items for this content type. In the example, the collection retrieves the Speaker related data items per the Session title field as soon as the first Session item from the collection requests its related data items. 

The following code snippet demonstrates how to use the template for retrieving the related data items for the Sessions example, described above: 

For a detailed tutorial about utilizing the Related data custom field, see Tutorial: Create DevReach site with related data feature.

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Web Security for Sitefinity Administrators

The free standalone Web Security lesson teaches administrators how to protect your websites and Sitefinity instance from external threats. Learn to configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?