Created
June 17, 2025 06:53
-
-
Save KayeeNL/6251b03f602c00079f902bfd50394c7f to your computer and use it in GitHub Desktop.
Sitecore Content Hub CreateEntityIterator Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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