Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save KayeeNL/6415285b44acd9424056c74414195cfb to your computer and use it in GitHub Desktop.
Save KayeeNL/6415285b44acd9424056c74414195cfb to your computer and use it in GitHub Desktop.
Sitecore Content Hub QueryAsync Example
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