c# - Linq Count Unique Values in List -


i need count of unique items in list of orders.

i have list of orders, , each order has list of items.

public class order {    public int orderid;    public list<items> itemlist; }  public class item {    public int itemid;    public int itemquantity;    public string itemdescription; } 

my end goal list of unique items (based on itemid or itemdescription) total count of each unique item.

i have following far, unsure next:

var x = order in orders items in order.orderitems group // know need group them here select new { // have count in here }; 

i need outcome this:

  • id: item_01, count: 15
  • id: item_02, count: 3
  • id: item_03, count: 6

any or direction on great. thanks.

this sum using both itemid , itemdescription values:

var x = order in orders             item in order.orderitems             group item new { itemid = item.itemid, itemdescription = item.itemdescription } g             select new { itemid = g.key.itemid, itemdescription = g.key.itemdescription, count = g.sum(o => o.itemquantity) }; 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -