Orchardcms Orchard CMS按ID订购项目
我需要列出具有不同Orchardcms Orchard CMS按ID订购项目,orchardcms,orchardcms-1.8,Orchardcms,Orchardcms 1.8,我需要列出具有不同ItemTypes的项目。这些类型由不同的部分组成。 默认内容查询以升序返回按ID排序的项目。我需要按降序获得列表 IContentQuery.OrderByDescending()方法需要泛型参数(TRecord:ContentPartRecord),我应该使用它来构建排序凭证。但正如我所说,我的内容类型有不同的部分 某些项不包含公共部分或标题部分,因此我无法将它们用作获取ContentItem.ID的参数 我的实际代码如下所示: private IContentQuery&
ItemType
s的项目。这些类型由不同的部分组成。
默认内容查询以升序返回按ID排序的项目。我需要按降序获得列表
IContentQuery.OrderByDescending()
方法需要泛型参数(TRecord:ContentPartRecord
),我应该使用它来构建排序凭证。但正如我所说,我的内容类型有不同的部分
某些项不包含公共部分
或标题部分
,因此我无法将它们用作获取ContentItem.ID
的参数
我的实际代码如下所示:
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;
}
private IContentQuery GetContentQuery(){
IContentQuery=\u contentManager.query(VersionOptions.Latest,
Manager.DocConfig.Keys.ToArray();
if(Manager!=null){
开关(管理器排序){
case SortOrder.Id:返回查询;
//返回query.OrderByDescending(cpr=>cpr.Id);
案例分类。已出版:
返回query.OrderByDescending(cpr=>cpr.publishedDutc);
案例排序器。标题部分:
返回query.OrderBy(tp=>tp.Title);
案例排序器。自定义:
var sf=Manager.SortFunc;
返回(sf==null)?查询:sf(查询);
}
}
返回查询;
}
有可能吗?公共零件上的创建日期是按创建日期排序的正确方式。使用id是一种可能以多种方式失败的黑客行为。公共部分实际上应该在所有内容类型上。关于
.OrderByDescending(c=>c.Id)如何代码>?@devqonContentItem
不直接包含ContentPartRecord
。其他Part
类继承自它。因此使用OrderByDescending()
会引发异常。每个contentiem
总是只包含InfoSetPart
,但它不是从ContentPart
继承的。你是对的,我的坏:)你为什么要按id排序?@BertrandLeRoy实际上我想按创建顺序排序(它们是相等的,对吗?),但无论如何,我没有在每个项目中都包含公共部分
,以获得CreationDate
。