如何通过double然后字符串来命令我的长LINQ查询的输出?

时间:2011-12-28 10:15:11

标签: c# linq

我有以下LINQ查询:

summaries = from m in _master
                            join d in _detail on pk + m.RowKey equals d.PartitionKey into outer
                            from d in outer.DefaultIfEmpty()
                            select new
                            {
                                Position = m.Position,
                                Title = m.Title,
                                Detail = ((d == null) ? 0 : 1),
                                PartitionKey = m.PartitionKey,
                                RowKey = m.RowKey,
                                Modified = m.Modified,
                                ModifiedBy = m.ModifiedBy
                            } into split
                            group split by split.Title into g
                            select new AdminSummary
                            {
                                Position = g.Last().Position,
                                Title = g.Key,
                                DetailCount = g.Sum(s => s.Detail),
                                PartitionKey = g.Last().PartitionKey,
                                RowKey = g.Last().RowKey,
                                Modified = g.Last().Modified,
                                ModifiedBy = g.Last().ModifiedBy
                            };

查询运行良好,但现在我想通过位置(双)跟随标题(字符串)进行排序。

有人可以建议我怎么做吗?

有人能告诉我怎么做订单吗?

2 个答案:

答案 0 :(得分:2)

这很简单:

summaries = summaries.OrderBy(item =>item.Position).ThenBy(item =>item.Title);

如果您需要按降序排列,也可以使用OrderByDescending()ThenByDescending()

答案 1 :(得分:1)

在上述查询后执行此操作。

summaries = from s in summaries
            orderby s.Position,s.Title
            select s