public void CreateCustomerProducts() { foreach (var item in CustomerList) { var ProductIds = InvoiceList.Where(x => x.Approval == true && x.CustomerID == item.ID).Select(x => x.ID).Distinct().ToList(); if (ProductIds.Count >= 0) { CustomerProductItem item1 = new CustomerProductItem(); item1.CustomerID = item.ID; item1.ProductIds = ProductIds; foreach (var item2 in ProductIds) { item1.ProductIdsString = item1.ProductIdsString + "," + item2; } if (item1.ProductIdsString != null) { item1.ProductIdsString = item1.ProductIdsString.Substring(1, item1.ProductIdsString.Length - 1); CustomerProducst.Add(item1); } } } }