try this:
Dictionary<int, int> SeatsByTableID = lstTables
.GroupBy(tbl => tbl.TableId)
.ToDictionary(grp => grp.Key, grp => grp.Count());
Note that I find your naming incongruent: if the table id is the integer, why do you call it 'noseats ?
I assume here your Class should be:
private class Table
{
public Table(int tableId, string seatcode)
{
this.TableId = tableId;
this.SeatCode = seatcode;
}
public int TableId { get; set; }
public String SeatCode { get; set; }
}
Update:
If you really want an IEnumerable;
var IESeatsByTableID = lstTables
.GroupBy(tbl => tbl.TableId)
.Select(grp => new {TblId = grp.Key, NSeats = grp.Count()});
Keep in mind the result is a:
{System.Linq.Enumerable.WhereSelectEnumerableIterator<system.linq.igrouping<int, fourformui.table="">, <>f__AnonymousType0<int, int="">>}
And, it's up to you to remember the internal field names, 'TableId and 'NSeats, when you use the IEnumerable.