Kentico 文档查询 API - 尝试匹配转发器结果

Kentico Document Query API - trying to match repeater results

我有一个 CMSRepeaterSelectOnlyPublished 设置为 true。为了实现延迟加载,我有一个为转发器加载更多项目的网络服务。我尝试过的文档查询(一次一个)如下:

var newsItems = tree.SelectNodes()
                .Types(pageTypes)
                .Path(path)
                .Where(whereStatement)
                .OrderBy(orderBy)
                .CombineWithDefaultCulture(false)
                .Page(page, count)
                .Columns(columns);

var newsItems = DocumentHelper.GetDocuments()
            .Types(pageTypes)
            .Path(path)
            .Where(whereStatement)
            .OrderBy(orderBy)
            .CombineWithDefaultCulture(false)
            .Page(page, count)
            .Published()
            .Columns(columns);

检查转发器和 API 生成的 Sql 查询后,似乎 API 在 where 语句中生成了一些额外的已发布检查(删除此结果在相同的数据库结果中,这将是我的目标)。

额外的 where 子句是:

DocumentCanBePublished] = 1 AND ([DocumentPublishFrom] IS NULL OR [DocumentPublishFrom] <= @Now) AND ([DocumentPublishTo] IS NULL OR [DocumentPublishTo] >= @Now

所以我的问题是,如何在中继器中包含此子句?我只想要已发布的文档,并且认为转发器上的 SelectOnlyPublished=true; 就足够了。我想我可以将它硬编码到我的 WhereCondition 中,但这对我来说不合适。

复选框"Select only published"将在后台生成下面的语句。

在您的转发器 WHERE 条件中添加此语句:

([DocumentCanBePublished] = 1 AND ([DocumentPublishFrom] IS NULL OR [DocumentPublishFrom] <= GETDATE()) AND ([DocumentPublishTo] IS NULL OR [DocumentPublishTo] >= GETDATE()))

您可能认为它很难编码,但它只是配置一个 Web 部件。如果你想让它更动态,那么在 WHERE 条件中使用宏来设置 GetDate() 方法。