score:5

Accepted answer

.groupby(category => category.itemcategory); returns an enumerable of igrouping objects, where the key of each igrouping is a distinct itemcategory value, and the value is a list of moneyspent objects. so, you won't be able to simply drop these groupings into an observablecollection as you're currently doing.

instead, you probably want to select each grouped result into a new moneyspent object:

var finalquery = boughtitemstoday
    .groupby(category => category.itemcategory)
    .select(grouping => new moneyspent { itemcategory = grouping.key, itemamount = grouping.sum(moneyspent => moneyspent.itemamount);

boughtitems = new observablecollection<dbcontrol.moneyspent>(finalquery);

score:0

you can project each group to an anyonymous (or better yet create a new type for this) class with the properties you want:

var finalquery = boughtitemstoday.groupby(category => category.itemcategory);
                                 .select(g => new 
                                  { 
                                     itemcategory = g.key, 
                                     cost = g.sum(x => x.itemamount)
                                  });

the asqueryable() should not be needed at all since boughtitemstoday is an iquerable anyway. you can also just combine the queries:

var finalquery = boughtitemdb.boughtitems
                             .groupby(item => item.itemcategory);
                             .select(g => new 
                              { 
                                  itemcategory = g.key, 
                                  cost = g.sum(x => x.itemamount)
                              });

Related Query

More Query from same tag