score:2

Accepted answer

assuming the ownernames will be identical for all the items in the group then you could do something like:

var linqquery2 = (from f in linqquery.tolist()
    group f by f.ownerid into mygroup
    select new
    {
        ownername = mygroup.first().ownername,
        ordercount = mygroup.count()
    });

edit:

if you want to use the first item multiple times, i'd suggest you use the 'let' operator:

var linqquery2 = (from f in linqquery.tolist()
                    group f by f.ownerid into mygroup
                    let first = mygroup.first()
                    select new
                    {
                        ownername = first.ownername,
                        ordercount = mygroup.count()
                    });

score:1

try

        var linqquery2 = (from f in linqquery.tolist()
                          group f by f.ownername
                          into mygroup
                          select new
                                     {
                                         ownername = mygroup.key,
                                         ownercount = mygroup.count()
                                     });

alternately:

        var linqquery2 = linqquery.tolist()
            .groupby(f => f.ownername)
            .select(mygroup => new
                                {
                                    ownername = mygroup.key,
                                    ownercount = mygroup.count()
                                });

Related Query

More Query from same tag