1

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

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;

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

4

2 回答 2

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;
于 2013-07-23T01:08:06.683 回答
1

您需要删除 .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()”,系统会抛出错误。

于 2016-02-04T03:44:01.297 回答