【发布时间】:2022-07-21 16:35:11
【问题描述】:
给定以下对象:
public class Order
{
public int OrderID { get; set; }
public int TotalPrice { get; set; }
public List<OrderItem> Items { get; set; }
}
public class OrderItem
{
public string Name { get; set; }
public int Price { get; set; }
public string SKU { get; set; }
}
现在我有这个结构:
[
{
"order_id": 1,
"total_price": 700,
"items": [
{
"name": "cellphone",
"price": 500,
"sku": "1s4f"
},
{
"product_name": "airphones",
"product_price": 200,
"sku": "1ar4"
}
]
},
{
"order_id": 2,
"total_price": 5000,
"products_info": [
{
"name": "car",
"price": 2500,
"sku": "8y5t"
},
{
"name": "battery",
"price": 1500,
"sku": "5g3g"
},
{
"name": "insurance",
"price": 1000
"sku": "5r8f"
}
]
}
]
我想将第一个订单拆分为 2 个订单,每个订单包含一个项目,第二个订单拆分为 3 个订单,逻辑相同。 这样做的最佳清洁和可读方式是什么?
【问题讨论】:
-
所以您希望第一个商品是 2 个订单,具有相同的 Id,但只有一个商品?