5

(I'm using Sitecore 8.1 Update 3 with Glass Mapper.Sc version 4.1.1.66)

I've run into an issue where some of the properties of a Sitecore item are not being populated in code through Glass Mapper. The values in our Content Base item (Id, Name, Display Name, typical Sitecore fields) seem to be getting populated correctly, but the child item's fields (I'll call it Overview) aren't mapped at all. They're all strings but they all end up null, even though the Content Base's values look to be correct. We also have child class maps working in other areas of the same, so that may not be the cause here.

Earlier in this project, we had an issue with Glass Mapper where field names that included spaces were not being read. However, I've made sure to leave out any spaces in field names, but this doesn't solve the issue.

Another possible contributor to the issue is that we have multiple languages on the site, so it's conceivable that language fallback may be complicating things. However, we have fallback enabled and working properly across the site without issues. (EDIT: I have tried applying the VersionCountDisabler, but that didn't help.)

I can post code if needed, but for the most part, it's just POCO's and mapping classes.

Any ideas on what other parts I should be looking into?

EDIT: Adding code

Mapping class:

namespace TheProject.Sc.Feature.Asset.Model.Configuration
{
[ExcludeFromCodeCoverage] 
public class IAssetOverviewModelMap : SitecoreGlassMap<IAssetOverviewModel>
{
    public override void Configure()
    {
        Map(config =>
        {
            ImportMap<IContentBase>();
            config.AutoMap();
            config.Field(f => f.HeaderPrefix).FieldName("AssetOverviewContentHeaderPrefix");
            config.Field(f => f.MarkUnitUnavailableText).FieldName("AssetOverviewContentMarkUnitUnavailableText");
            config.Field(f => f.PdfButtonText).FieldName("AssetOverviewContentPdfButtonText");
            config.Field(f => f.EditRecordButtonText).FieldName("AssetOverviewContentEditRecordButtonText");
            config.Field(f => f.SaveButtonText).FieldName("AssetOverviewContentSaveButtonText");
        });
    }
}
}

And here's a working mapping, which is called above and does just fine.:

namespace TheProject.Sc.Foundation.Model.Configuration
{
   public class IContentBaseMap : SitecoreGlassMap<IContentBase>
   {
      public override void Configure()
      {
         Map(config =>
         {
            config.AutoMap();
            config.Id(m => m.Id);
            config.Info(m => m.Name).InfoType(SitecoreInfoType.Name);
            config.Info(m => m.DisplayName).InfoType(SitecoreInfoType.DisplayName);
            config.Info(m => m.Path).InfoType(SitecoreInfoType.Path);
            config.Info(m => m.Url).InfoType(SitecoreInfoType.Url);
            config.Info(m => m.FullPath).InfoType(SitecoreInfoType.FullPath);
            config.Info(m => m.TemplateName).InfoType(SitecoreInfoType.TemplateName);
            config.Info(m => m.TemplateId).InfoType(SitecoreInfoType.TemplateId);
            config.Field(f => f.Sortorder).FieldName("__Sortorder"); // This line always returns 0, even when Sortorder is set differently
         });
      }
   }
}
  • 1
    Please include the code of all classes that correspond to relevant item templates. – Dmytro Shevchenko Nov 1 '16 at 17:43
  • 1
    If you could post a simple example of your mapping classes that aren't working, that will greatly help. – Kasaku Nov 1 '16 at 17:43
  • I'll be editing this above, but I found that the FieldName mapping in IContentBaseMap is also not returning the right value. (Always 0, even after I updated it). So, it looks like just FieldName mapping is causing issues, while id and infotype mappings do just fine. – Chris Weiss Nov 1 '16 at 18:13
2

After some experimentation, I found the cause of the issue.

If you look at the IAssetOverviewModelMap code above, you'll see this line:

config.Field(f => f.HeaderPrefix).FieldName("AssetOverviewContentHeaderPrefix");

The field name seems kinda long, right? We were prepending the category name onto the field name in order to avoid any duplicate names in items since we do a fair amount of inheritance.

That's where the problem lies. When I removed the "AssetOverviewContent" from the field names, everything worked fine. Based on this, I did some more experimentation.

I found that field names up to 23 characters long worked just fine. 24 or more and they won't map. I have no idea why this number in particular is the limit, but my guess is that there's some other mapping going on somewhere that's hitting a limit.

A little more experimentation also found that mapping using FieldId also doesn't work. Guids are going to be more than 23 characters long, so that makes some sense. However, you can't really do a guid in less than 23 characters so I can't confirm.

I may end up looking at the Glass Mapper code sometime soon to see if I can track down the answer. But now that I know there's a problem, I can avoid it.

2

Glass doesn't impose any length limitations on field names so I would be surprised if it was this.

We normally find that these kinds of intermittent issues are caused because the properties haven't been marked as virtual. If you can post your models as part of the question this will be easy to see.

Thanks

Mike

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.