Created
June 17, 2025 06:50
-
-
Save KayeeNL/6415285b44acd9424056c74414195cfb to your computer and use it in GitHub Desktop.
Sitecore Content Hub QueryAsync 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; | |
const int BatchSize = 1000; | |
int skip = 0; | |
bool hasMore = true; | |
var referenceEntities = new List<IEntity>(); | |
var mClient = new MClient("https://your-contenthub-url", "your-client-id", "your-client-secret"); | |
var memoryCache = new MemoryCache(new MemoryCacheOptions()); | |
while (hasMore) | |
{ | |
var query = Query.CreateQuery(entities => | |
from e in entities | |
where e.DefinitionName == "Uxbee.M.DemoEntity" | |
select e | |
); | |
query.Skip = skip; | |
query.Take = BatchSize; | |
var result = await mClient.Querying.QueryAsync(query, EntityLoadConfiguration.Full); | |
referenceEntities.AddRange(result.Items); | |
hasMore = result.Items.Count == BatchSize; | |
skip += BatchSize; | |
} | |
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