0

I'm using System.Linq.Dynamic to group a list of objects into a new grouped list of list of objects with the both code:

Dim lstGroupedFilterNew = lstDataSource _
                .GroupBy("New (Unit_ID, Itinerary_ID Driver_ID)", "grp") _
                .[Select](Function(grp) grp.ToList()).ToList()

But i'm get error lambda expression cannot be converted to 'string' because 'string' is not a delegate type on my select clause.

Renan Barbosa
  • 1,046
  • 3
  • 11
  • 31

1 Answers1

0

I chose not to use Linq.Dynamic, I discovered a way to verify conditions to dynamically add the keys to my GroupBy clause, the result is this:

Dim lstGroupedFilter = (From t In lstDataSource Group t By __groupByKey1__ = _
                          New With {Key .Unit_ID = (If(blnUnit, t.Unit_ID, 0)), Key .Itinerary_ID = If(blnItinerary, t.Itinerary_ID, 0), Key .Driver_ID = If(blnDriver, t.Driver_ID, 0)} _
                          Into g = Group Select g.ToList()).ToList()

This is an option to dynamically add keys and generate a result similar to this solution.

Renan Barbosa
  • 1,046
  • 3
  • 11
  • 31