DataQuery.GenerateQueryText Paged query cannot be generated without the orderBy set

Brenden Kehren asked on August 13, 2014 01:52

I'm using the new DataQuery methods to get my documents and it errors out when I try to bind the results to a grid. Here is my somewhat simple query:

    DataClassInfo dci = DataClassInfoProvider.GetDataClassInfo(className);
    if (dci != null)
    {
        string orderColumns = "BlogPostDate";
        if (className.ToLower() == "bluepillar.resource")
        {
            orderColumns = "NodeLevel, NodeOrder, NodeName";
        }

        var docs = DocumentHelper.GetDocuments(className)
                    .OnSite(SiteContext.CurrentSiteName)
                    .Path(aliasPath, PathTypeEnum.Children)
                    .Culture("en-us")
                    .OrderBy(OrderDirection.Descending, orderColumns)
                    .CombineWithDefaultCulture(true);

        docs.Offset = offset;
        docs.MaxRecords = 6;
        gv1.DataSource = docs.Execute();
        gv1.DataBind();
    }

This is the exact error:

[DataQuery.GenerateQueryText]: The paged query cannot be generated without the orderBy set.

Any ideas on what's going on?

Recent Answers


Jim Spillane answered on August 13, 2014 04:40

Maybe orderColumns should be an array:

string[] orderColumns = { "BlogPostDate" };

1 votesVote for this answer Mark as a Correct answer

Bill Tran answered on August 13, 2014 19:00

You might need to use .Page(int pageIndex, int pageSize)

instead of

    docs.Offset = offset;
    docs.MaxRecords = 6;
1 votesVote for this answer Mark as a Correct answer

Yehuda Lando answered on August 13, 2014 19:34

Happens with Page as well. Removing the .CombineWithDefaultCulture() fixed it for me. Might be a bug.

1 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on August 14, 2014 17:14

Kentico Support stated its a limitation with pre 8.1 and has been resolved in the new release (8.1) scheduled for next week.

1 votesVote for this answer Mark as a Correct answer

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