2011-08-16 43 views
5

Estoy tratando de convertir lo siguiente en vb.net. Gracias de antemanoNo se puede convertir esto en VB.net

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() }); 

Aquí es donde se queda bloqueado, he intentado dos métodos diferentes, pero aún nada funciona:

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) 

o

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() } 

Respuesta

0

Prueba esto:

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() _ 
}) 

Clase de objeto (Objeto nuevo) Con {}) es diferente del tipo anónimo (Nuevo con {}).

Puede utilizar este sitio en el futuro: http://www.developerfusion.com/tools/convert/csharp-to-vb/. Funciona bastante bien para la mayoría de las conversiones.

+0

Gracias Matthieu, ¡este método funcionó! Recordaré probar tu enlace de conversión arriba. – user896917

0

intente lo siguiente

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()}) 
+0

Gracias JaredPar ¡su solución también funcionó tan bien! Lo cual también podría darte una marca de verificación verde. Gracias :) – user896917

Cuestiones relacionadas