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.

Get started with Integration Hub | Sitefinity Cloud | Sitefinity SaaS

This free lesson teaches administrators, marketers, and other business professionals how to use the Integration hub service to create automated workflows between Sitefinity and other business systems.

Web Security for Sitefinity Administrators

This free lesson teaches administrators the basics about protecting yor Sitefinity instance and its sites from external threats. 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?