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() }
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With