2

I am using GlassMapper V3 and Sitecore 7.2. with MVC.

Sitecore item data is mapped automatically through the GlappMapper pipeline and the model is not very complex. The model has been extended by a partial class to also have the child items mapped automatically:

[SitecoreQuery("./*[@@templatename='Slider Element']", IsRelative = true)]
public virtual IEnumerable<Slider_Element> SliderElements { get;set; }

That works fine so far. But:

If one or more child items do not have a version in the current context language I would like to receive anyway. This works automatically for PageEditMode but not for the normal mode. But any kind of language fallback is not useful because this functinality should only be available for specific properties. What I would need is something like this:

[SitecoreQuery("./*[@@templatename='Slider Element']", IsRelative = true, GetItemsHavingNoVersions = true)]
public virtual IEnumerable<Slider_Element> SliderElements { get;set; }

As I know, GlassMapper is customizable at serveral points but did not find anything so far where I can add such functionality.

I also spent several hours searching the web and discovering the GlassMapper sourcecode.

There is a method in the SitecoreService class that seems to do parts of the logic but I am not 100% sure:

public IEnumerable<T> Query<T>(string query, bool isLazy = false, bool inferType = false) where T : class
    {
        return CreateTypes( typeof(T), () => { return Database.SelectItems(query); }, isLazy, inferType) as IEnumerable<T>;
    }

Thank you very much in advance for your help!

best regards, Thomas

Wesley Lomax
  • 2,067
  • 2
  • 20
  • 34
DrDrakken
  • 37
  • 7

1 Answers1

2

Have you tried using VersionCountDisabler

Wrap your calling code in a using statement

using(new VersionCountDisabler()){

  var model =  sitecoreService.GetItem<MyModel>("/sitecore/content/home");

}

Check out the Glass site for more information - http://www.glass.lu/Mapper/Sc/Documentation/VersionCountDisabler

Or you can disable the check globally

protected void Application_BeginRequest()
{
    Sitecore.Context.Items["Disable"] = new VersionCountDisabler();
}
Wesley Lomax
  • 2,067
  • 2
  • 20
  • 34
  • Hi Wesley! Thank you for your answer. This will not work for me because I do not receive the object like that. The items should be mapped automatically by the pipeline processor of sitecore mvc and GlassMapper. – DrDrakken Oct 02 '15 at 11:50
  • Have you seen this question http://stackoverflow.com/questions/26637652/how-to-enable-versioncountdisabler-for-glass-mapper-in-sitecore-for-sitecorequer perhaps that will help or you can disable the VersionCountDisabler globally from Global.asax.cs – Wesley Lomax Oct 02 '15 at 12:03
  • Hi Wesley! Thank you for the link. The post you mentioned seems to be exactly what I need. I did not find it by search because I did not know about VersionCount Disabler ;) – DrDrakken Oct 02 '15 at 12:10