I could have multiple (upto 5) IEnumerable<ResortSupplier>
and would like to consolidate them into single IEnumerable<ResortSupplier>
grouping by SupplierCode. My objects looks like this:
Here are my objects:
[Serializable]
public class ResortSupplier
{
public string SupplierCode { get; set; }
public IList<Product> ResortProducts { get; set; }
}
[Serializable]
public class Product
{
public string Code { get; set; }
//Other fields...
public IList<PerPricing> PricingDetail { get; set; }
}
[Serializable]
public class PerPricing
{
//Other fields..
public decimal? Price { get; set; }
public Error PricingError { get; set; }
}
Data in multiple IEnumerable could look like this:
----------------------------------------
IEnumerable<ResortSupplier> - 1
Hyatt Resort
Standard Room
PricingDetail-1
Superior Room
PricingDetail-1
Sandals Resort
Standard Room
PricingDetail-1
Delux Room
PricingDetail-1
----------------------------------------
IEnumerable<ResortSupplier> - 2
Hyatt Resort
Standard Room
PricingDetail-2
Superior Room
PricingDetail-2
One Bed Room Suit
PricingDetail-2
Sandals Resort
Standard Room
PricingDetail-2
Honeymoon Suit
PricingDetail-2
----------------------------------------
IEnumerable<ResortSupplier> - 3
.....
----------------------------------------
IEnumerable<ResortSupplier> - 4
.....
----------------------------------------
IEnumerable<ResortSupplier> - 5
.....
----------------------------------------
My consolidated result should contain:
IEnumerable<ResortSupplier> - Consolidated
Hyatt Resort
Standard Room
PricingDetail-1
PricingDetail-2
Superior Room
PricingDetail-1
PricingDetail-2
Bed Room Suit
PricingDetail-2
Sandals Resort
Standard Room
PricingDetail-1
PricingDetail-2
Delux Room
PricingDetail-1
Honeymoon Suit
PricingDetail-2
----------------------------------------
What is the best way to handle this? I tried simple IEnumerable.Union and GroupBy clauses but doesn't get me the results I want.
If I'm understanding you, you should use Concat to get them into one big collection, then you can group however you want
IEnumerable<ResortSupplier> master =
result1.Concat(result2).Concat(result3); //etc
Then group like you normally would:
var resultGrouped = master.GroupBy(rs => rs.SupplierCode);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With