Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save KayeeNL/6251b03f602c00079f902bfd50394c7f to your computer and use it in GitHub Desktop.
Save KayeeNL/6251b03f602c00079f902bfd50394c7f to your computer and use it in GitHub Desktop.
Sitecore Content Hub CreateEntityIterator Example
using Stylelabs.M.Sdk.WebClient;
using Stylelabs.M.Base.Querying;
using Stylelabs.M.Framework.Essentials.LoadConfigurations;
using Microsoft.Extensions.Caching.Memory;
var mClient = new MClient("https://your-contenthub-url", "your-client-id", "your-client-secret");
var memoryCache = new MemoryCache(new MemoryCacheOptions());
var query = Query.CreateQuery(entities =>
from e in entities
where e.DefinitionName == "Uxbee.M.DemoEntity"
select e
);
var iterator = mClient.Querying.CreateEntityIterator(query, EntityLoadConfiguration.Full);
var referenceEntities = new List<IEntity>();
while (await iterator.MoveNextAsync())
{
var batch = iterator.Current.Items;
referenceEntities.AddRange(batch);
}
memoryCache.Set("ReferenceEntities", referenceEntities, TimeSpan.FromHours(1));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment