I get this error when I try to group by CellID
:
Cannot implicitly convert type 'System.Collections.Generic.List
System.Linq.IGrouping int,p2pControllerLogAnalyser.Models.GSMData' to
'System.Collections.Generic.List
p2pControllerLogAnalyser.Models.GSMData'
public List<GSMData> GetCellID()
{
return Gsmdata.GroupBy(x => x.CellID).ToList();
}
What am I doing wrong and how can I fix it?
Best Answer
If you really need to do this, though I can't imagine why, you'll need to flatten the per-group enumerables into a single list using
SelectMany
:Of course, this looks like you are trying to batch items with the same
CellID
together, so you could always simply order it:Further to your comments, distinct
CellID
values can be returned thus:If you wish to return an ID and a count of grouped data, you can bundle that into an anonymous type:
Though if you are returning this from a method I'd make a discoverable type and not use an anonymous type.