Reputation: 722
I have a the following query but showing error. how can GroupBy ?
IList<tbl_roadmapautomation> allproductdata = _context.tbl_roadmapautomation.GroupBy(p=>p.Stream).ToList();
Here "Stream" is a column name which i want to GroupBy.
ERROR: Cannot implicitly convert type 'System.Collections.Generic.List>' to 'System.Collections.Generic.IList'. An explicit conversion exists (are you missing a cast?)
Please suggest me how can solve this error.Advance thanks for the help.
Upvotes: 0
Views: 2229
Reputation: 9702
Using var is nice when used inside a method, but what if you need to assign the data to a property that is needed for binding purposes. In this case,
public class RoadMapViewModel
{
IList<IGrouping<int, tbl_roadmapautomation>> allproductdata {get; set;}
// constructor
public RoadMapViewModel(){
allproductdata = _context.tbl_roadmapautomation.GroupBy(p=>p.Stream).ToList();
}
}
Upvotes: 0
Reputation: 70529
var allproductdata =
_context.tbl_roadmapautomation.GroupBy(p=>p.Stream).ToList();
will work
You need convert from this result to an IList<> (eg, with a cast).
But I don't think you want to -- IList is just the interface definition, why would you want a list like that?
Upvotes: 2