Sorting children on ContentSavedNotification

, , , ,

You can either call the .GetChildren function located in the ContentService or you set up a umbraco context and do something like this:

using var ctx = _umbracoContextFactory.EnsureUmbracoContext();
var children = ctx.UmbracoContext.Content!.GetById(parentId).Children()

Taken from the full file here (https://github.com/patrickdemooij9/CardGameDBSites/blob/63746877f2568f3570877385c6209bf16c81fb32/SkytearHorde.Website/EventHandlers/CardSortingEventHandler.cs#L16).

Differences between the two are: ContentService will always call the database while the UmbracoContext will also try to get them from the cache first.

1 Like