繁体   English   中英

如何将两个平面列表组合成一个嵌套的 object

[英]How to combine two flat lists into one nested object

我有三个列表,每个集合中包含三个相同的属性。 我想将结果合并到一个集合中。 Ex类结构如下

public class Order
{
    public int ProductId { get; set; }
    public int CustomerId { get; set; }
    public int OrderId { get; set; }

    // Few other Properties of OrderDetail
}
public class PaymentDetail
{
    public int ProductId { get; set; }
    public int CustomerId { get; set; }
    public int OrderId { get; set; }
    // Few other Properties form PaymentDetail
}

public class CouponUsageDetail
{
    public int ProductId { get; set; }
    public int CustomerId { get; set; }
    public int OrderId { get; set; }
    // Few other Properties form CouponUsageDetail
}

This type of output is coming from one API service where each class is in form of list object (JSON format) and we need to perform some operations on this. 所有三个属性(ProductId、CustomerId、OrderId)在每个集合中都包含相同的值,这意味着所有三个属性在每个集合中都重复。 我们需要对这些 collections 进行一些查找。 所以在正常情况下,我们可以用它来做 - 从订单列表开始一个 foreach 并过滤 PaymentDetail 和 CouponUsageDetail 的所有三个匹配属性。 但是当数据大小增加时,性能方面的成本会更高。 所以想到了预先制作嵌套结构并避免查找。 如果我们将 output 嵌套如下,这将有助于避免查找 PaymentDetail 和 CouponUsageDetail。 例如 - 我们收到以下格式的 JOSN

{"Orders":[{"ProductId":301,"CustomerId":101,"OrderId":201},{"ProductId":701,"CustomerId":501,"OrderId":601}],"PaymentDetails":[{"ProductId":301,"CustomerId":101,"OrderId":201},{"ProductId":701,"CustomerId":501,"OrderId":601}],"CouponUsageDetails":[{"ProductId":301,"CustomerId":101,"OrderId":201},{"ProductId":701,"CustomerId":501,"OrderId":601}]}

和这个 output 我们想形成 object 为

public class OrderDetails
{
    public int ProductId { get; set; }
    public int CustomerId { get; set; }
    public int OrderId { get; set; }
    // Few other Properties of OrderDetail

    List<PaymentDetail> PaymentDetail { get; set; }
    List<CouponUsageDetail> CouponUsageDetail { get; set; }
}

您能否指导一下,linq 的最佳最佳用法是什么,我们可以结合所有这三个匹配属性并使其更好地成为一个嵌套结构? 谢谢你! 注意:我知道这个结构需要规范化,但请忽略这里的规范化规则,因为这不在我们的控制范围内。

我有三个列表,每个集合中包含三个相同的属性。 我想将结果合并到一个集合中。 Ex类结构如下

public class Order
{
    public int ProductId { get; set; }
    public int CustomerId { get; set; }
    public int OrderId { get; set; }

    // Few other Properties of OrderDetail
}
public class PaymentDetail
{
    public int ProductId { get; set; }
    public int CustomerId { get; set; }
    public int OrderId { get; set; }
    // Few other Properties form PaymentDetail
}

public class CouponUsageDetail
{
    public int ProductId { get; set; }
    public int CustomerId { get; set; }
    public int OrderId { get; set; }
    // Few other Properties form CouponUsageDetail
}

This type of output is coming from one API service where each class is in form of list object (JSON format) and we need to perform some operations on this. 所有三个属性(ProductId、CustomerId、OrderId)在每个集合中都包含相同的值,这意味着所有三个属性在每个集合中都重复。 我们需要对这些 collections 进行一些查找。 所以在正常情况下,我们可以用它来做 - 从订单列表开始一个 foreach 并过滤 PaymentDetail 和 CouponUsageDetail 的所有三个匹配属性。 但是当数据大小增加时,性能方面的成本会更高。 所以想到了预先制作嵌套结构并避免查找。 如果我们将 output 嵌套如下,这将有助于避免查找 PaymentDetail 和 CouponUsageDetail。 例如 - 我们收到以下格式的 JOSN

{"Orders":[{"ProductId":301,"CustomerId":101,"OrderId":201},{"ProductId":701,"CustomerId":501,"OrderId":601}],"PaymentDetails":[{"ProductId":301,"CustomerId":101,"OrderId":201},{"ProductId":701,"CustomerId":501,"OrderId":601}],"CouponUsageDetails":[{"ProductId":301,"CustomerId":101,"OrderId":201},{"ProductId":701,"CustomerId":501,"OrderId":601}]}

和这个 output 我们想形成 object 为

public class OrderDetails
{
    public int ProductId { get; set; }
    public int CustomerId { get; set; }
    public int OrderId { get; set; }
    // Few other Properties of OrderDetail

    List<PaymentDetail> PaymentDetail { get; set; }
    List<CouponUsageDetail> CouponUsageDetail { get; set; }
}

您能否指导一下,linq 的最佳最佳用法是什么,我们可以结合所有这三个匹配属性并使其更好地成为一个嵌套结构? 谢谢你! 注意:我知道这个结构需要规范化,但请忽略这里的规范化规则,因为这不在我们的控制范围内。

我有三个列表,每个集合中包含三个相同的属性。 我想将结果合并到一个集合中。 Ex类结构如下

public class Order
{
    public int ProductId { get; set; }
    public int CustomerId { get; set; }
    public int OrderId { get; set; }

    // Few other Properties of OrderDetail
}
public class PaymentDetail
{
    public int ProductId { get; set; }
    public int CustomerId { get; set; }
    public int OrderId { get; set; }
    // Few other Properties form PaymentDetail
}

public class CouponUsageDetail
{
    public int ProductId { get; set; }
    public int CustomerId { get; set; }
    public int OrderId { get; set; }
    // Few other Properties form CouponUsageDetail
}

This type of output is coming from one API service where each class is in form of list object (JSON format) and we need to perform some operations on this. 所有三个属性(ProductId、CustomerId、OrderId)在每个集合中都包含相同的值,这意味着所有三个属性在每个集合中都重复。 我们需要对这些 collections 进行一些查找。 所以在正常情况下,我们可以用它来做 - 从订单列表开始一个 foreach 并过滤 PaymentDetail 和 CouponUsageDetail 的所有三个匹配属性。 但是当数据大小增加时,性能方面的成本会更高。 所以想到了预先制作嵌套结构并避免查找。 如果我们将 output 嵌套如下,这将有助于避免查找 PaymentDetail 和 CouponUsageDetail。 例如 - 我们收到以下格式的 JOSN

{"Orders":[{"ProductId":301,"CustomerId":101,"OrderId":201},{"ProductId":701,"CustomerId":501,"OrderId":601}],"PaymentDetails":[{"ProductId":301,"CustomerId":101,"OrderId":201},{"ProductId":701,"CustomerId":501,"OrderId":601}],"CouponUsageDetails":[{"ProductId":301,"CustomerId":101,"OrderId":201},{"ProductId":701,"CustomerId":501,"OrderId":601}]}

和这个 output 我们想形成 object 为

public class OrderDetails
{
    public int ProductId { get; set; }
    public int CustomerId { get; set; }
    public int OrderId { get; set; }
    // Few other Properties of OrderDetail

    List<PaymentDetail> PaymentDetail { get; set; }
    List<CouponUsageDetail> CouponUsageDetail { get; set; }
}

您能否指导一下,linq 的最佳最佳用法是什么,我们可以结合所有这三个匹配属性并使其更好地成为一个嵌套结构? 谢谢你! 注意:我知道这个结构需要规范化,但请忽略这里的规范化规则,因为这不在我们的控制范围内。

我有三个列表,每个集合中包含三个相同的属性。 我想将结果合并到一个集合中。 Ex类结构如下

public class Order
{
    public int ProductId { get; set; }
    public int CustomerId { get; set; }
    public int OrderId { get; set; }

    // Few other Properties of OrderDetail
}
public class PaymentDetail
{
    public int ProductId { get; set; }
    public int CustomerId { get; set; }
    public int OrderId { get; set; }
    // Few other Properties form PaymentDetail
}

public class CouponUsageDetail
{
    public int ProductId { get; set; }
    public int CustomerId { get; set; }
    public int OrderId { get; set; }
    // Few other Properties form CouponUsageDetail
}

This type of output is coming from one API service where each class is in form of list object (JSON format) and we need to perform some operations on this. 所有三个属性(ProductId、CustomerId、OrderId)在每个集合中都包含相同的值,这意味着所有三个属性在每个集合中都重复。 我们需要对这些 collections 进行一些查找。 所以在正常情况下,我们可以用它来做 - 从订单列表开始一个 foreach 并过滤 PaymentDetail 和 CouponUsageDetail 的所有三个匹配属性。 但是当数据大小增加时,性能方面的成本会更高。 所以想到了预先制作嵌套结构并避免查找。 如果我们将 output 嵌套如下,这将有助于避免查找 PaymentDetail 和 CouponUsageDetail。 例如 - 我们收到以下格式的 JOSN

{"Orders":[{"ProductId":301,"CustomerId":101,"OrderId":201},{"ProductId":701,"CustomerId":501,"OrderId":601}],"PaymentDetails":[{"ProductId":301,"CustomerId":101,"OrderId":201},{"ProductId":701,"CustomerId":501,"OrderId":601}],"CouponUsageDetails":[{"ProductId":301,"CustomerId":101,"OrderId":201},{"ProductId":701,"CustomerId":501,"OrderId":601}]}

和这个 output 我们想形成 object 为

public class OrderDetails
{
    public int ProductId { get; set; }
    public int CustomerId { get; set; }
    public int OrderId { get; set; }
    // Few other Properties of OrderDetail

    List<PaymentDetail> PaymentDetail { get; set; }
    List<CouponUsageDetail> CouponUsageDetail { get; set; }
}

您能否指导一下,linq 的最佳最佳用法是什么,我们可以结合所有这三个匹配属性并使其更好地成为一个嵌套结构? 谢谢你! 注意:我知道这个结构需要规范化,但请忽略这里的规范化规则,因为这不在我们的控制范围内。

我有三个列表,每个集合中包含三个相同的属性。 我想将结果合并到一个集合中。 Ex类结构如下

public class Order
{
    public int ProductId { get; set; }
    public int CustomerId { get; set; }
    public int OrderId { get; set; }

    // Few other Properties of OrderDetail
}
public class PaymentDetail
{
    public int ProductId { get; set; }
    public int CustomerId { get; set; }
    public int OrderId { get; set; }
    // Few other Properties form PaymentDetail
}

public class CouponUsageDetail
{
    public int ProductId { get; set; }
    public int CustomerId { get; set; }
    public int OrderId { get; set; }
    // Few other Properties form CouponUsageDetail
}

This type of output is coming from one API service where each class is in form of list object (JSON format) and we need to perform some operations on this. 所有三个属性(ProductId、CustomerId、OrderId)在每个集合中都包含相同的值,这意味着所有三个属性在每个集合中都重复。 我们需要对这些 collections 进行一些查找。 所以在正常情况下,我们可以用它来做 - 从订单列表开始一个 foreach 并过滤 PaymentDetail 和 CouponUsageDetail 的所有三个匹配属性。 但是当数据大小增加时,性能方面的成本会更高。 所以想到了预先制作嵌套结构并避免查找。 如果我们将 output 嵌套如下,这将有助于避免查找 PaymentDetail 和 CouponUsageDetail。 例如 - 我们收到以下格式的 JOSN

{"Orders":[{"ProductId":301,"CustomerId":101,"OrderId":201},{"ProductId":701,"CustomerId":501,"OrderId":601}],"PaymentDetails":[{"ProductId":301,"CustomerId":101,"OrderId":201},{"ProductId":701,"CustomerId":501,"OrderId":601}],"CouponUsageDetails":[{"ProductId":301,"CustomerId":101,"OrderId":201},{"ProductId":701,"CustomerId":501,"OrderId":601}]}

和这个 output 我们想形成 object 为

public class OrderDetails
{
    public int ProductId { get; set; }
    public int CustomerId { get; set; }
    public int OrderId { get; set; }
    // Few other Properties of OrderDetail

    List<PaymentDetail> PaymentDetail { get; set; }
    List<CouponUsageDetail> CouponUsageDetail { get; set; }
}

您能否指导一下,linq 的最佳最佳用法是什么,我们可以结合所有这三个匹配属性并使其更好地成为一个嵌套结构? 谢谢你! 注意:我知道这个结构需要规范化,但请忽略这里的规范化规则,因为这不在我们的控制范围内。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM