Best practice for querying linked items when field allows both reusable and page content types

2026/01/13 11:10 PM

We're working with Kentico Xperience by Kentico on .NET 9 and need guidance on handling linked content fields that can reference both reusable content types and web page types.

Our Scenario:

We have a PodcastContent reusable content type with GuestInfo and Hosts fields. In the Content Type configuration, these fields allow linking to:

Person - A reusable content type (IContentItemFieldsSource)

PersonPage - A web page type (IWebPageFieldsSource) that contains a linked Person via its PersonContentItem property

The Problem:

Since both types can be linked, the generated PodcastContent property type is:

IEnumerable<IContentItemFieldsSource>

Our current code fails unless we explicitly change the generated file to:

IEnumerable<Person>


Our Questions:

In the example I provided, I also have a HeroImage property that is also a Pages and reusable content type that Allowed Content Types is set to HeroImage and the generated code explicitly changed it to IEnumerable<HeroImage> but left the others generic (I assume purposefully)--do we need to account for each by casting the IContentItemFieldsSource or IWebPageFieldsSource to the correct object type first in code?

What is the recommended pattern for handling linked item fields that allow both reusable content types (IContentItemFieldsSource) and web page types (IWebPageFieldsSource)?

When using WithLinkedItems(depth), does Kentico automatically resolve the nested Person ContentItem on PersonPage, or do we need additional configuration? It wouldn't work unless I changed the type to IEnumerable<Person>

Should we restructure our content model to avoid mixing IContentItemFieldsSource and IWebPageFieldsSource in the same linked items field, or is this a supported scenario?

Thank you for your guidance on the recommended approach.

Environment

Tags:
Content management Content modeling

Answers

To response this discussion, you have to login first.