8

I have the following model

using System.Collections.Generic;
namespace Ignition.Foundation.Core.Models.BaseModels
{
    public interface INeedsChildren : IModelBase
    {
        IEnumerable<IModelBase> BaseChildren { get; set; }
    }
}
public interface IPage :  IMetadata, INavigation, ITaxonomy, INeedsChildren, IModelBaseWithMetadata, INeedsParent     {   }

public interface IIgnitionPage : IPage  {   }

Using AttributeMapping, the BaseChildren had the [SitecoreChildren] attribute.

I have an IPage model that implemented INeedsChildren, and that was in turn implemented by IIgnitionPage.

When using Attribute mapping, this worked as expected, and when I got a page reference I had the children.

Using Fluent mapping, I have the following mappers:

using Glass.Mapper.Sc.Maps;
using Ignition.Foundation.Core.Contracts;
using Ignition.Foundation.Core.Models.BaseModels;
namespace Ignition.Foundation.Core.Installers.Mappers
{
    public class NeedsChildrenMap : SitecoreGlassMap<INeedsChildren>, IGlassSettingsConsumer
    {
        public override void Configure()
        {
            Map(x =>
            {
                x.AutoMap().Cachable();
                ImportMap<IModelBase>();
                x.TemplateId(SettingsFactory.GetSitecoreSetting("Ignition.Map.Id.ModelBase"));
                x.Children(a => a.BaseChildren).InferType();
            });
        }

        public ISitecoreSettingsFactory SettingsFactory { get; set; }
    }
}

And the IgnitionPageMapper

public class IgnitionPageMapper : SitecoreGlassMap<IIgnitionPage>, IGlassSettingsConsumer
    {
        public override void Configure()
        {
            Map(x =>
            {
                ImportMap<IPage>();
                x.AutoMap().Cachable();
                x.TemplateId(SettingsFactory.GetSitecoreSetting("Ignition.Feature.Core.Map.Id.IgnitionPage"));
            });
        }
        public ISitecoreSettingsFactory SettingsFactory { get; set; }
    }

And the Page Mapper

public class PageMapper : SitecoreGlassMap<IPage>, IGlassSettingsConsumer
    {
        public override void Configure()
        {
            Map(x =>
            {
                ImportMap<IMetadata>();
                ImportMap<INavigation>();
                ImportMap<ITaxonomy>();
                ImportMap<INeedsChildren>();
                ImportMap<INeedsParent>();
                ImportMap<IModelBaseWithMetadata>();
                x.AutoMap().Cachable();
                x.TemplateId(SettingsFactory.GetSitecoreSetting("Ignition.Map.Id.Page"));
            });
        }
        public ISitecoreSettingsFactory SettingsFactory { get; set; }
    }

Once I use Fluent mapping, I no longer get BaseChildren of my items. I DO get Parent however, and it is wired up the same way. Am I missing something here, or is this a bug in Glass?

  • Jon you can get around this by running a query instead of using .Children in the mean time. – ASura Nov 11 '16 at 21:02
5

So after discussing with Nathanael Mann, it appears that this is indeed a defect in the Mapping code in Glass and not an issue with the implementation. I'll be adding a defect on the Github page and closing this question with this answer.

1

After playing with this for a bit I found out that if you name the Property Children then it'll work.

Not ideal, but if you are intent on using Fluent mapping and willing to adhere to that naming then it'll get you there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.