cant group by using linq

Asked By hq
22-Aug-10 08:01 AM
Earn up to 0 extra points for answering this tough question.
i am using vb.net and dataset have two table and relation , i query only on the first table but i cant use group by on any filed of the table it give Definition of method 'GroupBy' is not accessible in this context here is the code

Dim Groups = From n In dataSetTableAsEnumerable _
             
Group n By n.filedName  Into Group _
             
Select Group

  re: cant group by using linq

Peter Bromberg replied to hq
22-Aug-10 09:59 AM
I haven't used VB.NET for years, but in C# this works perfectly with the Nortwind Employees table

  var grps = from n in ds.Tables[0].AsEnumerable() group n by n["ReportsTo"into grp select grp;

you get 3 System.Linq.IGrouping objects each containing DataRows indexed on the "ReportsTo" group index.

I think your problem may be caused by using a reserved word "Group" as a variable.

  re: cant group by using linq

Chris replied to hq
31-Aug-10 11:56 AM
Add to the top of your code (before the class/namespace definitions):

Imports System.Linq

Create New Account