Here's what I did in K13R1.
- Export the code of your page types and add the generated code files to your solution.
- Add the following extension.
After this, you can access all base page fields without errors.
using CMS.DataEngine;
using CMS.DocumentEngine;
using System.Collections.Generic;
using System.Linq;
namespace Code.Extensions
{
public static class MultiDocumentQueryExtensions
{
public static MultiDocumentQuery InheritsType(
this MultiDocumentQuery query, string baseClassName)
{
// get base class
DataClassInfo basePageClassInfo = DataClassInfoProvider
.GetDataClassInfo(baseClassName);
// get all inheritors of this base class
List<DataClassInfo> basePageInheritors = DataClassInfoProvider
.GetClasses()
.WhereEquals(
nameof(DataClassInfo.ClassInheritsFromClassID),
basePageClassInfo.ClassID)
.ToList();
// break if there are none
if (!basePageInheritors.Any())
{
return query;
}
// return filtered query
List<string> typeList = new List<string>();
foreach(DataClassInfo type in basePageInheritors)
{
typeList.Add(type.ClassName);
}
return query.Types(typeList.ToArray());
}
}
}
Use it like this:
using Code.Extensions;
using CMS.DocumentEngine.Types.MySiteName;
[...]
MultiDocumentQuery query = DocumentHelper
.GetDocuments()
.InheritsType(BasePage.CLASS_NAME)
.WhereFalse(nameof(BasePage.BasePageTeaserIsHidden));