Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't convert this into VB.net

I'm trying to convert the following into vb.net. Thanks in advance

   Categories.DataSource = objDT.Rows.Cast<DataRow>()
        .Select(r => new { Attendee = r.Field<string>("Attendee"), Item = r.Field<string>("Item") })
        .GroupBy(v => v.Attendee)
        .Select(g => new { Attendee = g.Key, Item = g.ToList() });

This is where I get stuck, I have tried two different methods but still nothing works:

Categories.DataSource = objDT.AsEnumerable() _
    .Select(Function(r) New With {.Attendee = r.Field(Of String)("Attendee"), .Item = r.Field(Of String)("Item")}) _
    .GroupBy(Function(v) v.Field(Of String)("Attendee")) _
    .Select(Function(g) Attendee = g.Key)

or

Categories.DataSource = objDT.Rows.Cast(Of DataRow)().AsEnumerable _
    .Select New Object(){ Function(r As DataRow) Attendee = r.Field(Of String)("Attendee"), Item = r.Field(Of String)("Item")} _
.GroupBy( Function(v) v.Category) _
.Select( Function(g) new { Category = g.Key, Numbers = g.ToList() }
like image 611
user896917 Avatar asked Nov 14 '22 18:11

user896917


1 Answers

Try this :

  Categories.DataSource = objDT.Rows.Cast(Of DataRow)().Select(Function(r) New With { _
 .Attendee = r.Field(Of String)("Attendee"), _
 .Item = r.Field(Of String)("Item") _
}).GroupBy(Function(v) v.Attendee).Select(Function(g) New With { _
 .Attendee = g.Key, _
 .Item = g.ToList() _
})

Object Class (New Object() With {})is different than anonymous type (New With {}).

You can use this site in the future : http://www.developerfusion.com/tools/convert/csharp-to-vb/ . It works pretty well for most of the conversions.

like image 102
Matthieu Avatar answered Dec 20 '22 21:12

Matthieu