筛选Umbraco 7中的PropertyTypeAlias

筛选Umbraco 7中的PropertyTypeAlias,umbraco,umbraco7,Umbraco,Umbraco7,我有一个内容存储库,包含两个部分,职业类别和分支 我为每一个都创建了一个过滤器,下面您可以找到职业类别的代码。这很好用。现在,我想为过滤器的每个项目显示可见内容节点的数量 内容节点包含两个属性,它们是设置为仅选择一个的内容选择器 职业类别选择器的属性别名为函数 这不起作用,它总是给我0,但我已经创建了一个内容页。我错过了什么 @inherits Umbraco.Web.Macros.PartialViewMacroPage @* This snippet takes all of th

我有一个
内容存储库
,包含两个部分,
职业类别
分支

我为每一个都创建了一个过滤器,下面您可以找到
职业类别的代码。这很好用。现在,我想为过滤器的每个项目显示可见内容节点的数量

内容节点包含两个属性,它们是设置为仅选择一个的内容选择器

职业类别
选择器的属性别名为
函数

这不起作用,它总是给我0,但我已经创建了一个内容页。我错过了什么

@inherits Umbraco.Web.Macros.PartialViewMacroPage

@*
    This snippet takes all of the career categories to create a filter
*@

@{

    // Take the content repository node
    IPublishedContent contentRepository = Umbraco.ContentAtRoot().DescendantsOrSelf("ContentElements").FirstOrDefault();

    // Take the career categories node
    var careerCategorieRep = contentRepository.Children.Where("DocumentTypeAlias == \"ucCareersCategoryRepository\"").FirstOrDefault();

    // Take the careers list content node
    IPublishedContent careersList = Umbraco.ContentAtRoot().DescendantsOrSelf("CareersList").FirstOrDefault();

}

<ul class="col-md-12 col-sm-6 aside-widget-container">
    <li class="widget">
        <div class="title">
            <h3>Beroep</h3>
        </div>
        <ul class="menu">
            @* // Loop over the categories *@
            @foreach (var careerCategorie in careerCategorieRep.Children.Where("Visible").OrderBy("Name").ToList())
            {
                // Here I need to filter on the career category to get the amount of visible nodes in the content
                var count = careersList.Children.Where("Visible && function == " + careerCategorie.Id).Count();

                <li><a href="@careerCategorie.Id">@careerCategorie.Name<i class="fa fa-angle-right"></i></a></li>
            }
        </ul>
    </li>
</ul>

我需要获取具有特定属性值的可见页面的数量,例如,Id为职业类别的内容选择器。

首先,您可能应该使用
TypedContentRoot
而不是
ContentRoot
。TypedContent是从Umbraco.config xml缓存而不是数据库中检索的,因此速度应该更快

根据你的解释,我想你是说这条线是问题所在

var careerCategorieRep = contentRepository.Children.Where("DocumentTypeAlias == \"ucCareersCategoryRepository\"").FirstOrDefault();
换成

var contentRepository.Children.FirstOrDefault(n => n.DocumentTypeAlias == "ucCareersCategoryRepository");

应该这样做。

首先,您可能应该使用
TypedContentRoot
而不是
ContentRoot
。TypedContent是从Umbraco.config xml缓存而不是数据库中检索的,因此速度应该更快

根据你的解释,我想你是说这条线是问题所在

var careerCategorieRep = contentRepository.Children.Where("DocumentTypeAlias == \"ucCareersCategoryRepository\"").FirstOrDefault();
换成

var contentRepository.Children.FirstOrDefault(n => n.DocumentTypeAlias == "ucCareersCategoryRepository");

好的,我的另一个答案有一些好的建议,但我认为你的问题可能是别的

如果要搜索可见节点,这取决于文档类型中名为
umbracanavihide
的属性。属性应为true/false数据类型

如果要隐藏节点,必须将此属性添加到文档类型,然后将其设置为true(选中)

那么你可以用任何一种

myNode.Children.Where("Visible")
或者(只是为了说明编写lambda过滤器表达式的方法)

或者(最后一个只是为了说明umbracanavihide只是文档类型上的一个属性)

myNode.Children.Where(x=>x.GetPropertyValue(“umbracanaviHide”)==“1”)

好的,我的另一个答案有一些好的建议,但我认为你的问题可能是别的

如果要搜索可见节点,这取决于文档类型中名为
umbracanavihide
的属性。属性应为true/false数据类型

如果要隐藏节点,必须将此属性添加到文档类型,然后将其设置为true(选中)

那么你可以用任何一种

myNode.Children.Where("Visible")
或者(只是为了说明编写lambda过滤器表达式的方法)

或者(最后一个只是为了说明umbracanavihide只是文档类型上的一个属性)

myNode.Children.Where(x=>x.GetPropertyValue(“umbracanaviHide”)==“1”)

好的,我找到了解决方案:

我需要用引号将Id括起来,因为它存储为字符串而不是int

var count = careersList.Children.Where("Visible && function == \"" + careerCategorie.Id + "\"").Count();

好的,我找到了解决方案:

我需要用引号将Id括起来,因为它存储为字符串而不是int

var count = careersList.Children.Where("Visible && function == \"" + careerCategorie.Id + "\"").Count();

不,这不是问题,查看我的更新。它正在对无效的内容选择器属性进行筛选。不,这不是问题,请查看我的更新。它正在对不起作用的内容选择器属性进行筛选。