using System.Collections.Generic;
public static void Main()
var productInformationItems = new List<ProductTermAndPricingDataItem>();
productInformationItems.Add(new ProductTermAndPricingDataItem(125,"Month",(decimal)10.00,"Wholesale"));
productInformationItems.Add(new ProductTermAndPricingDataItem(125,"Year",(decimal)20.00,"Wholesale"));
productInformationItems.Add(new ProductTermAndPricingDataItem(126,"Month",(decimal)20.00,"Wholesale"));
productInformationItems.Add(new ProductTermAndPricingDataItem(126,"Year",(decimal)30.00,"Wholesale"));
productInformationItems.Add(new ProductTermAndPricingDataItem(127,"Month",(decimal)40.00,"Wholesale"));
productInformationItems.Add(new ProductTermAndPricingDataItem(127,"Year",(decimal)50.00,"Wholesale"));
List<ProductPricingGetDataItem> grouped = productInformationItems.GroupBy(
(key, g) => new ProductPricingGetDataItem() { ProductID = key, Terms = g.Select(x => new Terms(x.BillingPeriodName, x.PriceAmount)).ToList() }).ToList();
foreach(ProductPricingGetDataItem item in grouped)
public class ProductTermAndPricingDataItem {
public int ProductID { get; set; }
public string BillingPeriodName { get; set; }
public decimal PriceAmount { get; set; }
public string PriceTypeName { get; set; }
public ProductTermAndPricingDataItem(int id, string period, decimal amount, string priceType) {
BillingPeriodName = period;
PriceTypeName = priceType;
public class ProductPricingGetDataItem
public int ProductID { get; set; }
private List<Terms> _terms = new List<Terms>();
public override string ToString()
return string.Format("{0} => [{1}]", ProductID, String.Join(" | ", Terms.Select(x => x.ToString())));
public string Term { get; set; }
public decimal Price { get; set; }
public Terms(string term, decimal price)
public override string ToString()
return string.Format("{0};{1}", Term, Price);