Why isn't my Enumerable getting populated by G

2019-02-28 09:00发布

问题:

I'm totally confused as to why this isn't working. I have a class with a list of other classes as a property of it:

public class Widget
{
     ....
     public virtual IEnumerable<WidgetButton> Buttons { get; set; }
}

[SitecoreType(TemplateId = "{B615973D-59F6-437E-9827-BA3A40068C69}", AutoMap =true)]
public class WidgetButton : BasePage
{
     [SitecoreField]
     public virtual string Title { get; set; }
}

My sitecore item has a TreeListEx with one item in it:

and I'm reading this item thus:

Widget widgetTest = SitecoreContext.GetItem<Widget>(new Guid("{4FF5B96F-9606-4581-95F7-B6A7BAA4C28F}"));

My Widget(widgetTest) contains all of the data out of sitecore, but the buttons!? The Buttons property is just an empty list. What am I missing I've tried several configurations, Publishing, etc. According to the Glass.Mapper tutorials this should work


Glass configuration

Glass.Mapper.Sc.CastleWindsor.config

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
    <sitecore>
        <pipelines>
            <initialize>
                <processor type="RR.Web.Website.App_Start.GlassMapperSc, RR.Web.Website" />
            </initialize>
        </pipelines>
    </sitecore>
</configuration>

Glass.Mapper.Sc.Mvc.Config

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
      <settings></settings>
    <pipelines>



      <mvc.getModel>
        <processor type="Glass.Mapper.Sc.Pipelines.Response.GetModel, Glass.Mapper.Sc.Mvc"/>
      </mvc.getModel>

    </pipelines>
  </sitecore>
</configuration>

Going directly to sitecore I can get my item:

Sitecore.Data.Database context = Sitecore.Context.Database;
var item  = context.GetItem(new ID("{4FF5B96F-9606-4581-95F7-B6A7BAA4C28F}"));

item contains a field called Buttons, the value of this field is the GUID of the item in the treelist ({3C18BF9F-9906-4807-83B9-73CA08E61C39}).

If I query this directly I can see the button:

var buttonItem = context.GetItem(new ID("{3C18BF9F-9906-4807-83B9-73CA08E61C39}"));

so everything appears perfectly fine! Why isn't glass mapper mapping this?

回答1:

I got a solution, don't ask me why this works because I found it though trial and error. Basically doing this seemed to make it work:

[SitecoreType(AutoMap =true)]
public class Widget
{
     ....
     [SitecoreField(FieldType =SitecoreFieldType.TreelistEx)]
     public virtual IEnumerable<WidgetButton> Buttons { get; set; }
}

specifically I think specifying the FieldType.