here are the pieces of our selection code:
//Add the necessary columns
private string[] _resourceArticleColumns = new string[]
{
"ArticleName", "ArticleTitle", "ArticleTeaser", "RelatedArticlesList", "ArticleContent", "ArticleHeroImage", "ArticleTeaserImage", "NodeAliasPath", "ShowEmailForm", "CtaPath"
};
//Map the exported page type to the DTO object
private Func<ResourceArticle, ResourceArticlePageDto> ResourceArticleSelect => resourceArticle => new ResourceArticlePageDto()
{
Header = resourceArticle.ArticleTitle,
PageContent = resourceArticle.ArticleContent,
HeroImage = resourceArticle.Fields.ArticleHeroImage,
TeaserImage = resourceArticle.Fields.ArticleTeaserImage,
TeaserText = resourceArticle.ArticleTeaser,
NodeAliasPath = resourceArticle.NodeAliasPath,
ShowEmailForm = resourceArticle.ShowEmailForm,
SidebarCta = (!string.IsNullOrEmpty(resourceArticle.CtaPath) && resourceArticle.CtaPath != null) ? GetGlobalCtaByNodeGuid(resourceArticle.CtaPath) : null,
**RelatedArticles = resourceArticle.Fields.RelatedArticlesList**
};
//Run the document query using an interface
public ResourceArticlePageDto GetArticle(string nodeAliasPath)
{
return DocumentQueryService.GetDocument<ResourceArticle>(nodeAliasPath, true)
.AddColumns(_resourceArticleColumns)
.Select(ResourceArticleSelect)
.FirstOrDefault();
}
//Document query service that gets the page type
public DocumentQuery<TDocument> GetDocuments<TDocument>(bool loadBaseDtoFields = false) where TDocument : TreeNode, new()
{
var query = DocumentHelper.GetDocuments<TDocument>();
// Evaluates whether preview mode is enabled
if (SiteContext.IsPreviewEnabled)
{
if (loadBaseDtoFields)
_coreColumns.Concat(new[] { "HideChildrenFromNavigation", "HideFromNavigation" });
// Loads the latest version of pages as preview mode is enabled
query = query
.Columns(_coreColumns.Concat(new[] { "NodeSiteID" })) // Sets initial columns returned for optimization.
//Adds 'NoteSiteD' column required for the Preview mode.
.OnSite(SiteContext.SiteName) // There could be more sites with matching page
.LatestVersion()
.Published(false)
.Culture(SiteContext.PreviewCulture);
}
if (!SiteContext.IsPreviewEnabled)
{
// Loads the published version of pages
query = query
.Columns(_coreColumns) // Sets initial columns returned for optimization.
.OnSite(SiteContext.SiteName)
.Published()
.PublishedVersion()
.Culture(SiteContext.CurrentSiteCulture);
}
return query;
}
The bold line is where I am seeing the null reference error, which is actually happening in the generated code from Kentico at this point:
/// <summary>
/// Related Articles.
/// </summary>
public IEnumerable<TreeNode> RelatedArticlesList
{
get
{
return mInstance.GetRelatedDocuments("RelatedArticlesList");
}
}
RelatedArticlesList is an IEnumerable