本文介绍了为什么我的Enumerable不会被Glass.Mapper填充?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我完全困惑为什么它不起作用.我有一个带有其他类列表的类作为它的属性:

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; }
}

我的sitecore项具有一个TreeListEx,其中包含一项:

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}"));

我的Widget(widgetTest)包含所有来自站点核心的数据,但是按钮! Buttons属性只是一个空列表.我缺少的是我尝试了几种配置,发布等.根据 Glass.Mapper教程这应该有效

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.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>


直接转到sitecore,我可以得到我的商品:


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包含一个名为Buttons的字段,该字段的value是树列表({3C18BF9F-9906-4807-83B9-73CA08E61C39})中该项的GUID.

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}"));

所以一切看起来都很好! Glass Mapper为什么不映射呢?

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

推荐答案

我有一个解决方案,不要问我为什么可行,因为我通过反复试验发现了它.基本上,这样做似乎可以使它工作:

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; }
}

具体来说,我认为指定FieldType.

specifically I think specifying the FieldType.

这篇关于为什么我的Enumerable不会被Glass.Mapper填充?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 23:55