Content retriever

2025/10/03 8:17 AM

Hello,

I have following code to retrieve the data of page content type called special event page. Now it has one nested fields called calendar event which is reusable content type which contains two fields called start date and end date.


var builder = new ContentItemQueryBuilder()
    .ForContentType(
        GPHC.SpecialEventPage.CONTENT_TYPE_NAME,
        config => config
            .Where(where => where
                .WhereEquals(nameof(WebPageFields.WebPageItemID), webPageItemId))
            .WithLinkedItems(20)
            .ForWebsite(_webSiteChannelContext.WebsiteChannelName)
    )
    .InLanguage(_preferredLanguageRetriever.Get());

var queryExecutorOptions = new ContentQueryExecutionOptions
{
    ForPreview = _webSiteChannelContext.IsPreview
};

var specialEventPages = await _contentQueryExecutor.GetMappedWebPageResult<GPHC.SpecialEventPage>(builder, queryExecutorOptions);

Now when i inspect value it shows the data as follow [which is not correct.]

There is one more place where i retireve that calendar event using below code and data is showing the correct


Environment

 var contentItem = await GetContentType<GPHC.CalendarEvent>(
     indexedItem.ItemGuid,
     indexedItem.LanguageName,
     GPHC.CalendarEvent.CONTENT_TYPE_NAME);

private async Task<T?> GetContentType<T>(Guid id, string languageName, string contentTypeName)
    where T : IContentItemFieldsSource, new()
{
    const string source = nameof(GetContentType);
    if (id == Guid.Empty)
    {
        _eventLogService.LogWarning(source, "INVALID_GUID", "Provided GUID is empty.");
    }
    try
    {
        var query = new ContentItemQueryBuilder()
            .ForContentType(contentTypeName,
                config =>
                    config
                        .WithLinkedItems(10)
                        .Where(where => where.WhereEquals(nameof(WebPageFields.ContentItemGUID), id))
                        .TopN(1))
            .InLanguage(languageName);

        var options = new ContentQueryExecutionOptions();

        var result = await _queryExecutor.GetMappedResult<T>(query, options) ?? Enumerable.Empty<T>();

        return result.FirstOrDefault();
    }
    catch (Exception ex)
    {
        _eventLogService.LogException(source, "CONTENT_RETRIEVAL_ERROR", ex,
            $"Error retrieving content for GUID: {id}, Language: {languageName}, Type: {contentTypeName}");
        throw new ApplicationException("An error occurred while retrieving CalendarEvent content.", ex);
    }

Here is the result

Can you help what am i missing or is there anything wrong

Also in the db it showing the correct value. Also note that both fields are having text data type.

  • Xperience by Kentico version: [30.10.1]

  • .NET version: [8]

  • Execution environment: [SaaS]

Tags:
Content modeling Content querying Content types

Answers

2025/10/03 8:03 PM

I don't think this is related to your querying. Maybe your dates in the database aren't want you expect? How were the dates populated?

Xperience dates are saved using the local time of the application (server). The time selected in the datetime picker for date and time fields displays that time using the local time of the browser.

So, if my application is running in CET (Central European Time) and I look at dates in the database, they will all CET dates. If I am visiting an Xperience application from EST (Eastern Standard Time) and see a date in the content item form in the administration UI, Xperience will convert that CET time in the database to an EST time for me.


Also, a couple of notes on your example code.

  1. These are perfect scenarios for the Content Retriever API which handles applying the request context and caching for you, simplifying your query code significantly. We updated our Dancing Goat example project to the Content Retriever using AI agents to reduce the work. Using the Content Retriever you could get rid of your entire GetContentType<T> method.
  2. The WithLinkedItems() API tells Xperience how many levels of connected content to retrieve. Often, 4 levels is the most that are needed across an entire project. 10 and 20 seems like waaay to many. This number means you have a content model like Landing page -> Product -> FAQ -> Image -> ... 6 to 16 more linked items.
2025/10/04 11:24 AM

Hello, I have made the both fields as text input not date picker. In the database the the data is showing correct.

2025/10/07 7:07 PM

We cannot guarantee correct data transformation to/from dates if you use a text field instead of a date or date time field.

2025/10/09 8:58 AM

Just to be clear we are not transforming the data into any other data type. I just want to retrieve the data and render on the page. In the data base it shows correct data but when i debug it is showing date only. Also when i try to retrieve the data for indexing it shows the correct data.

Also i have done more debugging on this and found following points

  1. Previously i had 30.5.3 version and it was working fine. After upgrading to latest 30.10.1 this issue started occurring. No code changes beside the version upgrade has been done
  2. The calendar event content type has other fields with same data type and dat. Which is retrieving correctly. Only start date and end date is showing this issue.
  3. I tried to debug using sql profiler and found that the only date is being retrieved. Although it is text filed and time is also added there.
  4. When i add new filed called StartDateString with same configuration. It shows correct data.

My conclusion is that if field "SatartDate" and "EndDate might be causing this issue.". Or may be version upgrade code is responsible.[see point 1]

2025/10/16 6:19 AM

Hi!

There might be other circumstances which might have effect:

  • Are you viewing the data in preview mode or not?
  • Is that content item published or not (in combination with previous)
  • Do you have multilingual content, and which language are you viewing?
  • Is that specific data in a reusable field schema? If so, where did you look in the database for that content?

I've never seen this behaviour before, especially because you state that it is only those two string fields, and the other fields are still showing correctly.

To response this discussion, you have to login first.