【问题标题】:Telerik Sitefinity - Sorting data selectedTelerik Sitefinity - 选择的数据排序
【发布时间】:2013-07-22 11:05:04
【问题描述】:

我有下面的代码来检索数据

Type dType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Schedule.ScheduleManagement");

        // This is how we get the collection of event items
        var myCollection = dynamicModuleManager.GetDataItems(dType).Where(i => i.Status == ContentLifecycleStatus.Live && i.Visible && i.GetValue<string>("Title").ToString() == channel + " Schedule").FirstOrDefault();
        // At this point myCollection contains the items from the the type


        return myCollection;

知道如何对选定的数据进行排序吗?请帮忙。

【问题讨论】:

标签: telerik sitefinity


【解决方案1】:

首先,您需要删除 .FirstOrDefault(),因为它返回单个项目(或 null)而不是集合。

要在 linq 中进行排序,您需要使用 .OrderBy()

例如,这将按标题排序。

Type dType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Schedule.ScheduleManagement");

    // This is how we get the collection of event items
    var myCollection = dynamicModuleManager.GetDataItems(dType).Where(i => i.Status == ContentLifecycleStatus.Live && i.Visible && i.GetValue<string>("Title").ToString() == channel + " Schedule").OrderBy(p=> p.GetValue<string>("Title"));
    // At this point myCollection contains the items from the the type


    return myCollection;

【讨论】:

    【解决方案2】:

    您需要删除 .FirstOrDefault() 方法。 然后在查询中添加方法“.AsEnumerable()”,详见

    var dType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Schedule.ScheduleManagement");
    
    // This is how we get the collection of event items
    var myCollection = dynamicModuleManager.GetDataItems(dType)
                                           .AsEnumerable()
                                           .Where(i => i.Status == ContentLifecycleStatus.Live && i.Visible 
                                                       && i.GetValue<string>("Title").ToString() == channel + " Schedule")
                                           .OrderBy(p=> p.GetValue<string>("Title"));
    // At this point myCollection contains the items from the the type
    
    
    return myCollection;
    

    注意:如果不推送方法“.AsEnumerable()”,系统会报错。

    【讨论】:

      猜你喜欢
      • 2017-03-18
      • 2021-08-05
      • 1970-01-01
      • 2012-10-15
      • 1970-01-01
      • 2015-05-20
      • 1970-01-01
      • 1970-01-01
      • 2016-08-15
      相关资源
      最近更新 更多