Use Join queries with dynamic content types


When you work with dynamic content type, such as instances of the type Telerik.Sitefinity.DynamicModules.Model.DynamicContent, you may use various LINQ operations. This article demonstrates how to use the Join operation. 
For more information, see the MSDN »  Querable.Join method.

This article uses the terms TInner, TOuter, and TResult with the same meaning as the MSDN article.

Supported cases

Sitefinity CMS supports the following combinations of Join queries with generic types for outer and inner Join arguments:

  • Only TOuter is DynamicContent.
  • Only TInner is DynamicContent.
  • Both TOuter and TInner are DynamicContent.


Sitefinity CMS support all of these combinations with some requirements on TResult:

  • You must not use dynamic types directly anywhere.
  • You must return static, non-anonymous, custom result type for TResult.
You extract the required fields values into properties of the resulting custom static type. Using this technique, you avoid using the dynamic types directly.

The examples in this article contain the following:

  • The first example defines the JoinResult class that the other two code samples use.
  • The second example demonstrates how you must use Join queries.
  • The third example demonstrated how you must not use Join queries.

Example: Define the JoinResult class

The following code samples has a DynamicContent type Hotel. It containing the child type Room. To keep the results from the computation, the type JoinResults is introduced:

Example: Recommended usage

In the following code sample, you can find examples of how you must use the Join queries in Sitefinity CMS. The code sample demonstrates the following:

  • How to use static types as return results for LINQ queries.
    Instead of using dynamic types directly anywhere, return static, non-anonymous custom type for TResult, and extract the required fields values into properties of TResult.
  • How to work with Lstring values on DynamicContent types.
  • How to get values for specific culture when your site uses multilingual mode.

Example: Limitations

The following code sample demonstrates edge cases and limitations that, when used, will throw exceptions:

TOuter is DynamicContent type

In this case:

  • You cannot return dynamic type results as properties of objects. However, you can return dynamic type results directly (TResult is DynamicContent). In this case, you must use extension methods in Telerik.Sitefinity.Data.Linq.Dynamic to query them afterwards.
  • Complex type results are supported in this case, if dynamic type results are not used. However, you can extract properties of dynamic types and assign them to other properties on a new static type.
  • It is not possible to return anonymous object types.
  • It is not possible to return DynamicContent types on properties.

TInner or both TOuter and TInner are DynamicContent types

In these cases:

  • You can return anonymous types, but you cannot return dynamic types directly. 
    If you want to return dynamic objects in the result, you must wrap them as properties of anonymous return type. 
    Extension methods in Telerik.Sitefinity.Data.Linq.Dynamic do not work after the join. 
    You have to use standard LINQ extension methods in subsequent expressions. These extensions will work, if used in expressions that were passed as parameters to the Join.
  • It is not possible to return dynamic type directly. 
    Instead, wrap the dynamic types in anonymous objects or custom result objects.

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Get started with Integration Hub | Sitefinity Cloud | Sitefinity SaaS

This free lesson teaches administrators, marketers, and other business professionals how to use the Integration hub service to create automated workflows between Sitefinity and other business systems.

Web Security for Sitefinity Administrators

This free lesson teaches administrators the basics about protecting yor Sitefinity instance and its sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?