DocumentQuery API Question - GetDocuments() how to avoid Invalid Column name

Rick Lannan asked on January 20, 2016 02:13

Version: Kentico 9

I am trying to query my documents using the DocumentQuery API however the field in which I am using a whereContains is causing an error because not all documents contain that column. However the DocumentQuery API doesn't give me the option to use the MultiDocumentQuery GetDocuments method with more than one classname to strip out the objects that don't contain this column.

My query looks like this:-

            .ExcludePath("/Settings", PathTypeEnum.Section)
            .ExcludePath("/", PathTypeEnum.Single)
            .WhereContains("Species", "23");

Species is a property only on certain page-types. The error I'm receiving is "Caused exception: Invalid column name 'Species'."

Can anyone please advise how to amend my query to avoid this error?

Recent Answers

Virgil Carroll answered on January 20, 2016 07:04

You can filter the GetDocuments with a single class by changing it to GetDocuments("CMS.News"). This will return only records from that class...if you need to add multiple classes to get documents from, use the.Types("CMS.News", "CMS.Blog") as part of your query and just add the classes that have this column

1 votesVote for this answer Mark as a Correct answer

Martin Hejtmanek answered on January 20, 2016 09:26

In addition to what Virgil says, you can use apply specific parameters only to particular types, such as:

        .Type("Your.FirstType", q => q.WhereContains("Species", "23"))
        .Type("Your.SecondType", q => q.WhereContains("Foo", "Bar"));

We can give you more precise query if you tell us more details about your page types and data that you expect to query.

Also, if you only need some specific columns, make sure you use Columns parameterization to get better performance of the query. The default one gets more than 100 general page columns.

3 votesVote for this answer Mark as a Correct answer

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