2013-04-25 249 views
0

我试图使用某种模式来订购某些数据,并且需要一些帮助来了解如何执行此操作。我还没有看到使用排序依据子句中的LINQ查询的任何例子,我不完全知道如何在这种情况下对数据进行排序:通过字符串与字符串列表进行比较

public IList<UserEventModel> GetListData(IDictionary<string, IList<string>> criteria, IEnumerable<UserEventModel> subscriptions) 
{ 
    subscriptions = subscriptions.OrderBy(x => x.EntityType); 
} 

寻找扩展追加到的EntityType来比较的内容'标准'值对在这里的关键[2],例如x => x.EntityType.?(指定的值集合)

+0

的重复[C# - 基于排序的另一个列表LINQ的名单(http://stackoverflow.com/questions/3470098/linq-list-sort-based-on-another-list) ? – 2013-04-25 18:11:32

回答

1

你几乎是正确的。追加tolist并尝试

subscriptions = subscriptions 
        .OrderBy(x => x.EntityType).ToList();