1
我有這個查詢返回一個IQueryable結果。排序IQueryable結果Linq
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)));
它給出了一個錯誤。
使用不工作的OrderByDescending編輯問題,以便我們可以看到您嘗試的內容。 – Esko
@Esko:更新.. – Isuru