Reference data batching

Version: 10.4

The Reference Data Client API supports batching, and it is recommended that you submit large amounts of data to the Reference Data Service as smaller batches. A batch is submitted when awaitclient.SaveAsync() is called. In the following example, two definitions are submitted in the same batch:

RequestResponse
using Sitecore.DependencyInjection;
using Sitecore.Xdb.ReferenceData.Core;
using System.Globalization;
using Sitecore.Xdb.ReferenceData.Core.Collections;

namespace Documentation
{
    public class RefDataSaveDefinition
    {
        public async void Example()
        {
            var client = ServiceLocator.ServiceProvider.GetService(typeof(IReferenceDataClient)) as IReferenceDataClient;

            var definitionType = await client.EnsureDefinitionTypeAsync("country");

            var definitionKey = new DefinitionKey("se", definitionType, 1);
            var definition = new Definition<string, string>(definitionKey)
            {
                IsActive = true
            };

            definition.CultureData[new CultureInfo("en")] = "Sweden";
            definition.CultureData[new CultureInfo("se")] = "Sverige";

            var definitionKey2 = new DefinitionKey("de", definitionType, 1);
            var definition2 = new Definition<string, string>(definitionKey)
            {
                IsActive = true
            };

            definition.CultureData[new CultureInfo("en")] = "Germany";
            definition.CultureData[new CultureInfo("se")] = "Tyskland";

            var definitions = new DefinitionCollection<string, string>
            {
                definition,
                definition2
            };

            await client.SaveAsync(definitions);
        }
    }
}
Note

If you are building an application that relies on batching, it is recommended that you provide a way for an administrator to configure and tune the default batch size.

Do you have some feedback for us?

If you have suggestions for improving this article,