I need to compare nested json collections against one another using C# linq. Here is an example of the json collections and the classes that they get bound to.
=== collection 1 ===
[
{
"contractId": "100-200-A",
"invoices": [
{
invoiceNumber: 987654
},
{
invoiceNumber: 555999
}
]
},
{
"contractId": "300-777-Z",
"invoices": [
{
invoiceNumber: 12345
},
{
invoiceNumber: 100025
}
]
}
]
public class Contract
{
public string ContractId { get; set; }
public IList<Invoice> Invoices { get; set; }
public class Invoice
{
public int InvoiceNumber { get; set; }
}
}
=== collection 2 ===
[
{
"paymentDate": "01/01/2000",
"contracts":[
{
"contractId": "100-200-A",
"invoices": [
{
invoiceNumber: 987654
},
{
invoiceNumber: 555999
},
{
invoiceNumber: 444333
},
{
invoiceNumber: 111000
}
]
},
{
"contractId": "300-777-Z",
"invoices": [
{
invoiceNumber: 12345
},
{
invoiceNumber: 100025
},
{
invoiceNumber: 888666
},
{
invoiceNumber: 222999
}
]
}
]
}
]
public class PaymentRequest
{
public DateTime PaymentDate { get; set; }
public IList<ContractList> Contracts { get; set; }
public class ContractList
{
public string ContractId { get; set; }
public IList<InvoiceList> Invoices { get; set; }
}
public class InvoiceList
{
public int InvoiceNumber { get; set; }
}
}
Assuming that the contractId's are the same in both collections, I can create a linq join between the two, I am having a hard time trying to find the extra invoices that are in the 2nd collection set. Essentially, I need to get back a list of all the invoice numbers for that specific contractId that are in the 2nd collection that are not present in the 1st collection.
InvoicevsInvoiceListandContractvsContractList?