Kentico文档查询API始终返回空结果

时间:2018-02-13 16:37:35

标签: content-management-system kentico

我有以下查询:

var newsItems = tree.SelectNodes()
                .Types(pageTypesArray)
                .Path(path)
                .OrderBy(orderBy)
                .CombineWithDefaultCulture(false)
                .Page(page, count)
                .OnCurrentSite()
                .NestingLevel(-1)
                .Culture(CurrentDocument.DocumentCulture)
                .InCategories(categories)
                .TopN(topN)
                .Where("ListableDocumentImage is not null AND ListableDocumentImage != ''")
                .Columns(columns);

翻译如下:

WITH AllData AS 
(
    SELECT  TOP 6 * for brevity, ROW_NUMBER() OVER (ORDER BY [NewsOccurrenceDate] DESC) AS [CMS_RN] 
FROM View_CMS_Tree_Joined AS V WITH (NOLOCK, NOEXPAND) INNER JOIN SOS_News AS C WITH (NOLOCK) ON [V].[DocumentForeignKeyValue] = 
[C].[NewsID] AND V.ClassName = N'News' LEFT OUTER JOIN COM_SKU AS S WITH (NOLOCK) ON [V].[NodeSKUID] = [S].[SKUID] 
WHERE [NodeSiteID] = @NodeSiteID AND (([DocumentCanBePublished] = 1 AND ([DocumentPublishFrom] IS NULL OR [DocumentPublishFrom] <= @Now) 
AND ([DocumentPublishTo] IS NULL OR [DocumentPublishTo] >= @Now)) 
AND [NodeAliasPath] LIKE @NodeAliasPath AND [DocumentCulture] = @DocumentCulture 


**AND 0 = 1)** <<<------------------- WHERE DID THIS COME FROM?????
) 
SELECT  *, (SELECT COUNT(*) FROM AllData) AS [CMS_TOT] 


FROM AllData 
WHERE CMS_RN BETWEEN 4 AND 6 
ORDER BY CMS_RN

有没有人曾经遇到过这样的事情?我无法弄清楚为什么他们会坚持我的where子句中的AND 0=1

1 个答案:

答案 0 :(得分:1)

正确构建文档API调用将有助于此。在您的查询结果中,您可以看到您的WHERE条件甚至没有被添加,因此它确实会对被调用方法的顺序产生影响。

例如:

var newsItems = tree.SelectNodes()
                .Types(pageTypesArray)
                .Path(path)
                .Where("ListableDocumentImage is not null AND ListableDocumentImage != ''")
                .TopN(topN)
                .OrderBy(orderBy)
                .CombineWithDefaultCulture(false)
                .Page(page, count)
                .NestingLevel(-1)
                .Culture(CurrentDocument.DocumentCulture)
                .InCategories(categories)
                .OnCurrentSite()
                .Columns(columns);