I need to list items with different ItemTypes. These types consist of different parts.
Default content query returns items ordered by ID in ascending order. I need to get list in descending order.
IContentQuery<ContentItem>.OrderByDescending<TRecord>() method requires generic parameter (TRecord : ContentPartRecord), which I should use to build ordering creteria. But as I said my content types have different parts.
Some of items do not contain CommonPart or TitlePart, so I can't use them as parameter to get ContentItem.ID.
My actual code looks like this:
private IContentQuery<ContentItem> GetContentQuery() {
IContentQuery<ContentItem> query = _contentManager.Query(VersionOptions.Latest,
Manager.DocConfig.Keys.ToArray());
if (Manager != null) {
switch (Manager.SortBy) {
case SortOrder.Id: return query;
// return query.OrderByDescending<CommonPartRecord>(cpr => cpr.Id);
case SortOrder.Published :
return query.OrderByDescending<CommonPartRecord>(cpr => cpr.PublishedUtc);
case SortOrder.TitlePart :
return query.OrderBy<TitlePartRecord>(tp => tp.Title);
case SortOrder.Custom :
var sf = Manager.SortFunc;
return (sf == null) ? query : sf(query);
}
}
return query;
}
is it possible?
.OrderByDescending<ContentPartRecord>(c => c.Id);? - devqonContentItemdoes not containContentPartRecorddirectly. otherPartclasses inherite from it. So usingOrderByDescending<ContentPartRecord>()throws an exception. EachContenItemalways contains onlyInfoSetPart, but it doesn't inherite fromContentPart- teranCommonPartin each item to getCreationDate. - teran