5

We are int he process of upgrading out solution and found that some of our glass models are not populating. IPage implementations are not showing up values in the IGlassBase. Here are the sample models:

IPage

public interface IPage : IBasePage
{
    [SitecoreField]
    string Title { get; set; }
    [SitecoreField]
    string Body { get; set; }
}

IGlassBase

public interface IGlassBase
{
    Guid Id { get;  set; }

    Language Language { get;  set; }

    int Version { get;  set; }

    Guid BaseTemplateIds { get; set; }

    string TemplateName { get;  set; }

    Guid TemplateId { get; set; }

    string Name { get;  set; }

    string Url { get;  set; }
}

GlassGlassBaseMap

public class GlassGlassBaseMap : SitecoreGlassMap<IGlassBase>
{

    public override void Configure()
    {
        Map(x =>
        {
            x.AutoMap();
            x.Info(y => y.BaseTemplateIds).InfoType(SitecoreInfoType.BaseTemplateIds);
        });
    }
}
3
  • Does your IBasePage inherit from IGlassBase? Oct 7, 2016 at 16:59
  • yes Corey it does inherit from IGlassBase
    – ASura
    Oct 7, 2016 at 17:00
  • 1
    It looks like you are mixing fluent configuration with attribute configuration. Do you register both configuration loaders? Maybe posting your GlassMapperScCustom would help.
    – Ben Golden
    Oct 7, 2016 at 17:07

3 Answers 3

8

You can't mix configuration methods in Glass Mapper. Your IPage model is using attribute configuration but your IGlassBase model is using fluent configuration. Remove the SitecoreField attributes from your IPage properties or add SitecoreField attributes to all of your IGlassBase properties and remove your fluent configuration map.

1
  • 2
    Did it the other way round by adding fluent to the IPage and it started working. Thanks.
    – ASura
    Oct 7, 2016 at 17:09
0

You might need to add the [SitecoreType] attribute. Something like this:

[SitecoreType(TemplateId=MyTemplateIds.Page)]
public interface IPage : IBasePage
{
    [SitecoreField]
    string Title { get; set; }
    [SitecoreField]
    string Body { get; set; }
}
1
  • Thanks Ben but that is not helping. I tried to be specific with the interface and also the properties.
    – ASura
    Oct 7, 2016 at 16:54
0

ASURA - I think you need to make the properties on your model virtual.

This has tripped me up a few times before.

public interface IPage : IBasePage
{
    [SitecoreField]
    public virtual string Title { get; set; }
    [SitecoreField]
    public virtual string Body { get; set; }
}
5
  • Thanks but specifying that does not help this problem. For my interfaces I do not specify public nor do I virtual.
    – ASura
    Oct 7, 2016 at 17:02
  • 2
    Interfaces can't have virtual properties. Oct 7, 2016 at 17:02
  • Ahr sorry, didn't notice it was an interface. So adding a template Id attribute isn't working either. Are you field names called exactly what you have as the property names? Oct 7, 2016 at 17:04
  • Yeah, I usually use no spaces in my fields. That checks out as well.
    – ASura
    Oct 7, 2016 at 17:06
  • Ok, as otherwise I was going to say we usually decorate our properties like so and set the field name as a constant: [SitecoreField(FieldName = Fields.Title )] string Title { get; set; } If thats not the issue though that won't help. Oct 7, 2016 at 17:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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