Telerik Sitefinity - 选择的数据排序

时间:2013-07-22 11:05:04

标签: telerik sitefinity

我有以下代码来检索数据

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;

知道如何选择排序数据吗?请帮忙。

2 个答案:

答案 0 :(得分: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;

答案 1 :(得分:1)

您需要删除.FirstOrDefault()方法。 然后在查询中,您需要添加方法&#34; .AsEnumerable()&#34;,查看详细信息

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;

注意:如果你不推动方法&#34; .AsEnumerable()&#34;,系统会抛出错误。