Currently I have a list of the Activity class, this class, among other properties, has one that is IdOperario.
The thing is that I load all the activities of all the operators in the lAux list from the database and what I need is from that large list to be able to treat all the activities of each operator, for this I try to do the following:
As you can see it gives compilation error.
I would need to be able to treat all generated sublists with each different IdOperator within the foreach, or some similar treatment. Thanks for the help.
Edit: I put the code with Einer's modification, it works fine, the only thing is that it can be optimized.
Although @Einer's answer is totally correct, you are probably looking for a
GroupBy
more than aSelect
. If what you want is to see all the activities of each Operator, the most logical thing is to group them by the IdOperario to later go through each activity of said operator in a loop. I would do something like this:Or, if what you need is a list of each operator to process, simply:
IdOperario
is of typeint
and when you do it youSelect(x=>x.IdOperario)
are creating a list ofint
, not ofActividad
so it tells you that you cannot convert a typeint
toList<Actividad>
.So change:
By:
Update:
As you mention that you need to group by activity and that same class that has the data you need, you can use
GroupBy(x=>X.IdOperario)
where it will give you the list grouped byIdOperario
: