score:3

it is not a direct comparision and isn't on mono, but i have some code which does something similar with a 6mb xml file which i read into a dataset and it has 30,000 rows and takes 0.5 seconds, so i don't think it is the groupby itself that causes the problem.

to diagnose further, i would suggest

  • testing how long it takes to read the information into a list, ie

    var foolist = foostuff.asenumerable().tolist(); 
    
  • testing how long it takes if you change the query to use foolist instead of foostuff

  • testing how long it takes if you remove footier = g.min(foo => foo.tier) from the select

  • separate the .field<> reflection from the groupby and time each section, ie first read the information from the datatable into a list , eg

    var list2 =
    (from foo in foostuff.asenumerable()
    select new { 
        fooid = foo.field<int64>("fooid") 
        tier  = foo.field<int>("tier")
    }).tolist();
    

    then you can query this list

    var query =
    from foo in list2
    group foo by foo.fooid into g
    select new
    {
            fooid = g.key,
            footier = g.min(foo => foo.tier)
    };
    var results = query.tolist();
    

if this query is slow, it would suggest that there is something wrong with mono's implementation of groupby. you might be able to verify that by using something like this

    public static dictionary<tkey, list<tsrc>> testgroupby<tsrc, tkey>
     (this ienumerable<tsrc> src, func<tsrc,tkey> groupfunc)
    {
        var dict= new dictionary<tkey, list<tsrc>>();

        foreach (tsrc s in src)
        {
            tkey key = groupfunc(s);
            list<tsrc> list ;

            if (!dict.trygetvalue(key, out list))
            {
                list = new list<tsrc>();
                dict.add(key, list);
            }       
            list.add(s);        
            }

        return dict;
}

and to use it

  var results = list2.testgroupby(r=>r.fooid)
      .select(r=>  new { fooid = r.key, footier = r.value.min(r1=>r1.tier)} );

note, this is not meant as a replacement for groupby and does not cope with null keys but should be enough to determine if their is a problem with groupby (assuming mono's implementation of dictionary and list are ok).

score:5

you are materializing all the entities when you call asenumerable(), so your grouping is being done in memory. try removing that part so that the grouping is done at the database level:

var query =
        from foo in foostuff
        group foo by foo.fooid into g
        select new
        {
                fooid = g.key,
                footier = g.min(foo => foo.tier)
        };

Related Query

More Query from same tag