Frage

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.

War es hilfreich?

Lösung

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?

Andere Tipps

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(); 
        }
 }
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top