c# - Sitecore GlassMapper 尝试使用查询属性获取没有版本的项目

标签 c# sitecore sitecore7.2 glass-mapper

我正在使用 GlassMapper V3 和 Sitecore 7.2。使用 MVC。

Sitecore项目数据通过GlappMapper管道自动映射,模型不是很复杂。 该模型已通过分部类进行了扩展,还可以自动映射子项:

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

到目前为止效果很好。但是:

如果一个或多个子项目没有当前上下文语言的版本,我无论如何都希望收到。这对于 PageEditMode 自动起作用,但不适用于正常模式。但是任何类型的语言后备都是没有用的,因为这种功能应该只适用于特定的属性。我需要的是这样的:

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

据我所知,GlassMapper 在很多方面都是可定制的,但到目前为止还没有找到任何可以添加此类功能的地方。

我还花了几个小时在网络上搜索并发现了 GlassMapper 源代码。

SitecoreService 类中有一个方法似乎可以执行部分​​逻辑,但我不能 100% 确定:

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

预先非常感谢您的帮助!

最诚挚的问候, 托马斯

最佳答案

您是否尝试过使用VersionCountDisabler

将调用代码包装在 using 语句中

using(new VersionCountDisabler()){

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

}

查看 Glass 网站了解更多信息 - http://www.glass.lu/Mapper/Sc/Documentation/VersionCountDisabler

或者您可以全局禁用检查

protected void Application_BeginRequest()
{
    Sitecore.Context.Items["Disable"] = new VersionCountDisabler();
}

关于c# - Sitecore GlassMapper 尝试使用查询属性获取没有版本的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32905017/

相关文章:

sitecore - 为什么某些 Sitecore 内容不会被 Solr 索引?

在 visual studio 2012 中设置 sitecore 多站点

Sitecore Social Connector 2.1 无法与 Sitecore 7.2 配合使用

authentication - Sitecore - 阻止访问页面,但仍显示在导航中

sitecore - 为使用 Sitecore 中的小下拉框模板创建的卡盘项目设置数据源

Sitecore 日志文件重复错误

c# - WPF:数据绑定(bind)一个列表框,其中每个项目都是一个制表位

c# - 多次触发 TreeView AfterSelect 事件

c# - 如何在 C# 中的静态类中创建一个简单的回调

c# - DotnetCore 1.0.x 中的 TcpListener.BeginAcceptTcpClient I/O 模型是什么