gpt4 book ai didi

c# - 展平一个 ObservableCollection

转载 作者:太空宇宙 更新时间:2023-11-03 21:10:44 25 4
gpt4 key购买 nike

我有一个这样的集合:

Order //Collection
|-OrderId
|-DateOfOrder
|-PartyName
|-OrderDetails //Collection
| |-ItemName
| |-Quantity
| |-Rate
| |-Amount
|-Dispatch //Collection
| |-InvoiceNo
| |-DateOfDispatch
| |-DispatchDetails //Collection
| | |-ItemName
| | |-Quantity
| | |-Rate
| | |-Amount

现在我想展平这个集合,这样我就可以按照下面提到的模式显示数据:

OrderId | DateOfOrder | PartyName | InvoiceNo | DateOfDispatch | Dispatch ItemName | Dispatch Quantity | Dispatch Rate | Dispatch Amount
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |

我试过:

Orders = new ObservableCollection<Order>(orderService.GetAllOrders()
.SelectMany(x => x.Dispatches)
.SelectMany(x => x.DispatchDetails)
.ToList()
);

最佳答案

我不清楚 OrderDetails 和 DispatchDetails 之间的关系,您的数据结构中似乎缺少 DispatchItemTransactions。不管怎样,我希望你发现这个简单的方法有用:

foreach(var order in Orders)
foreach(var dispatch in order.Dispatches)
foreach(var dispatchDetail in dispatch.DispatchDetails)
{
// now construct your record object from order.OrderId, order.DateOfOrder, ... , dispatchDetail.Amount
}

关于c# - 展平一个 ObservableCollection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37922137/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com