SPSiteDataQuery: Filtering Content Types in SharePoint 2010

sharepointsharepoint-2010spsitedataquery

In SharePoint 2007 executing a SPSiteDataQuery with filter for content types worked as expected.

<Where>
  <Eq>
    <FieldRef Name='ContentType'/>
    <Value Type='Text'>SomeContentType</Value>
  </Eq>
</Where>

In SharePoint 2010 the same query only returns items from one list.
A possible workaround would be to filter on the content type id. A "BeginsWith" operator has to be used, since the "list content type" inherits from the "site content type":

<Where>
  <BeginsWith>
    <FieldRef Name='ContentTypeID'/>
    <Value Type='Text'>SomeContentTypeId</Value>
  </BeginsWith>
</Where>

But this would match all items with this content type or with any inherited content type. Which is not what I want.

Does anyone know how to create a SPSiteDataQuery with content type filter?

Best Answer

Try this (see the computed value type):

<Where>
  <Eq>
    <FieldRef Name='ContentType'/>
    <Value Type='Computed'>SomeContentType</Value>
  </Eq>
</Where>
Related Topic