我有这个查询返回一个IQueryable结果。
return supplierInvoices.Union(otherInvoices.Join(orders, invoice => invoice.OrderId, order => order.Id, (invoice, order) => new { Order = order, Invoice = (invoice as IReconcilableInvoiceEntity) }))
.GroupBy(m => m.Order)
.Where(m => m.Any())
.Select(m => new KeyValuePair<Order, IQueryable<IReconcilableInvoiceEntity>>(m.Key, m.Select(n => n.Invoice).AsQueryable()));
我需要按CreatedOn
列(datetime
)的降序对其进行排序。我尝试在此查询中使用orderbydescending(a => a.CreatedOn)
和orderbydescending(a=> a.Key.CreatedOn)
,但仍未提供预期结果。所有帮助赞赏。谢谢!
编辑 - 我尝试了什么
return supplierInvoices.Union(otherInvoices.Join(orders, invoice => invoice.OrderId, order => order.Id, (invoice, order) => new { Order = order, Invoice = (invoice as IReconcilableInvoiceEntity) }))
.GroupBy(m => m.Order)
.Where(m => m.Any())
.OrderByDescending(m => m.Key.CreatedOn)
.Select(m => new KeyValuePair<Order, IQueryable<IReconcilableInvoiceEntity>>(m.Key, m.Select(n => n.Invoice).AsQueryable()));
这不正确排序
另一次尝试
return supplierInvoices.Union(otherInvoices.Join(orders, invoice => invoice.OrderId, order => order.Id, (invoice, order) => new { Order = order, Invoice = (invoice as IReconcilableInvoiceEntity) }))
.GroupBy(m => m.Order)
.Where(m => m.Any())
.Select(m => new KeyValuePair<Order, IQueryable<IReconcilableInvoiceEntity>>(m.Key, m.Select(n => n.Invoice).AsQueryable().OrderByDescending(m => m.CreatedOn)));
会出错。
答案 0 :(得分:1)
如果您想按两列排序,则可以使用&#34; OrderByDescending(a =&gt; a.column1)&#34;其次是 &#34;的 ThenBy(A =&GT; a.column2)强>&#34;获得理想的结果。