Query with aggregate column

Yehuda Lando asked on August 14, 2014 19:22

Hi,

I have a query like this:

DocumentHelper.GetDocuments("MyClass")
.WhereEquals("NodeOwner", MembershipContext.AuthenticatedUser.UserID)
.HasResults();

When executing it, I get the error: Column 'View_CMS_Tree_Joined_Versions.ClassName' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

Same happens with this query:

DocumentHelper.GetDocuments(ToolNode.ToolClassName)
.Path(CurrentPageInfo.NodeAliasPath, PathTypeEnum.Children)
.Column(new CountColumn("ToolID").As("Count"))

Adding .GroupBy("ClassName", "NodeXML") fixes this, but I would rather just return the count column. Is there a why to do this?

Thanks

Recent Answers


Joshua Adams answered on August 14, 2014 22:50

Have you tried just using the DocumentHelper.GetDocuments() and adding the classname to the where clause?

0 votesVote for this answer Mark as a Correct answer

Yehuda Lando answered on August 15, 2014 21:21

Still the same. I still get this select: SELECT (COUNT(*)) AS Count, ClassName, NodeXML

0 votesVote for this answer Mark as a Correct answer

Martin Danko answered on December 1, 2014 12:59

Hello Yehuda,

Thank you for informing us about this issue. In order to determine if this is a bug, I have reported it to our development team.

Best regards, Martin

0 votesVote for this answer Mark as a Correct answer

Yehuda Lando answered on December 2, 2014 19:14

Thanks Martin

0 votesVote for this answer Mark as a Correct answer

Martin Danko answered on December 15, 2014 10:45

Hi Yehuda,

let update the status of this issue. It's really a bug.

Starting from the hotfix 8.1.16 you can use this workaround:

var query = DocumentHelper.GetDocuments()
.Type("CMS.MenuItem", q => q.Path("/%"))
.ResultColumns(new CountColumn("NodeID").As("Count"));

In the end our developers have found that this issue is more complex and they've decided to make a wider refactoring of the code, so they decided to fix it completely for Kentico 8.2 which will be released at the beginning of January.

Best regards, Martin

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.