سؤال

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.

هل كانت مفيدة؟

المحلول

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?

نصائح أخرى

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(); 
        }
 }
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top