Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mark 255 posts 612 karma points
    Nov 29, 2013 @ 11:05
    Mark
    0

    Getting IPublishedContent from the new Relations Service

    Using the new ApplicationContext.Current.Services.RelationService, I'm not seeing any way of retrieving IPublishedContent object sets. I see that it's possible to get IUmbracoEntity enumerables, but aren't these the slower read / write objects, like the Umbraco.Core.Models.ContentType?

    Is there some way of easily getting IPublishedContent object sets?

  • Brett Spencer 88 posts 259 karma points
    Jul 08, 2017 @ 00:29
    Brett Spencer
    0

    This is old... not so good that it doesn't have a reply. I'm on 7.6.3 and ran into the same issue.

    Trying to figure it out now.

    FYI: I'm in controller.

  • Brett Spencer 88 posts 259 karma points
    Jul 13, 2017 @ 22:09
    Brett Spencer
    100

    Here is my solution (Blog Example). I extracted this method out of the controller and use in in a "Helper" class:

        private static IEnumerable<BlogArticle> RelatedArticles(int id)
        {
            var umbracoHelper = new Umbraco.Web.UmbracoHelper(UmbracoContext.Current);
            IList<BlogArticle> list = new List<BlogArticle>();
            var service = ApplicationContext.Current.Services.RelationService;
            foreach (var relation in service.GetByParentId(id))
            {
                list.Add(new BlogArticle(umbracoHelper.Content(relation.ChildId)));
            }
            return list;
        }
    
Please Sign in or register to post replies

Write your reply to:

Draft