Error when Retrieving ContentType ()

2024/10/18 10:00 AM

An error occurs when retrieving a ContentType on the following line (with cache management, from documentation):

await linkedItemsDependencyRetriever.Get(items.Select(item => item.SystemFields.ContentItemID), maxLevel: 1).ToHashSet(StringComparer.InvariantCultureIgnoreCase);

ContentType Information:

This is one of the most recently created ContentType. A filter is applied to this ContentType based on several criteria (pagination, date, etc.).

Error Occurrence:

The error occurs when applying the filter under specific conditions. When the result set contains either zero or more than one item, everything works as expected. However, if the result contains exactly one item, an error is thrown.

Error Message:

{"There is no data in the SqlDataRecord enumeration. To send a table-valued parameter with no rows, use a null reference for the value instead."}

Debugging Insights:

Using the debugger, it appears the error originates from the Get() method of the WebPageLinkedItemsDependencyRetriever class. Specifically, when the error occurs, the private method GetContentItemCommonDataIds() does not return any IDs:

IList<int> contentItemCommonDataIds = GetContentItemCommonDataIds(webPageIds);  // Line 50

Answers

2024/10/19 3:59 PM

What does your ContentItemQueryBuilder query look like?

2024/10/28 8:16 AM

Here's the ContentItemQueryBuilder equivalent (we build the query in several stages depending on the values present in the filter) :

new ContentItemQueryBuilder().ForContentType(ContentTypeName, q => q
.Where(w => w.WhereGreaterOrEquals(nameof(CalendarEvent.Start), filter.MinDate.Value.Date))
.Where(w => w.WhereLessOrEquals(nameof(CalendarEvent.Start), filter.MaxDate.Value.Date)));

At the query creation stage, here's how we apply the DateTime filter (q is a ContentTypeQueryParameters type) :

        if (MinDate.HasValue) q.Where(w => w.WhereGreaterOrEquals(DateColumnName, MinDate.Value.Date));
        if (MaxDate.HasValue) q.Where(w => w.WhereLessOrEquals(DateColumnName, MaxDate.Value.Date.AddDays(1).AddMilliseconds(-1)));
2024/10/29 1:06 PM

The method that you identified is throwing the exception does the following:

var ids = provider.Get().Source(delegate (QuerySource source)
{
    source.InnerJoin<CMS.Websites.Internal.WebPageItemInfo>("ContentItemCommonDataContentItemID", "WebPageItemContentItemID");
}).WhereIn("WebPageItemID", webPageIds.ToList())
    .Column("ContentItemCommonDataID")
    .GetListResult<int>();

If webPageIds is null, has 0, 1, or more values it does not throw an exception, even if the identifiers are invalid webPageIds.

I tried to get ILinkedItemsDependencyAsyncRetriever and IWebPageLinkedItemsDependencyAsyncRetriever to throw exceptions by specifying only 1 value with the IEnumerable<int> method overload, but neither threw an exception.

I think the issue you are experiencing is caused by something else.

To answer this question, you have to login first.