Link to home
Start Free TrialLog in
Avatar of Adrian Cross
Adrian Cross

asked on

Return one column with a groupby query - List<int> anonymous type error

Hi, I want to store the values of one column (ColumnD) as a List<int> to use it as a look up later on.

           List<int> query = (from t in db.TABLE where t.RecordID == recordID 
                            group t by new { t.ColumnA, t.ColumnB,t.ColumnC }
                            into grp
                            select new { grp.ColumnD}).ToList();

            return query;

Open in new window


The code above gives me the following error:
'cannot implicitly convert from anonymous Generic.List type <..> to Generic List<int>'

if i return the query as an object instead, it works. Then I can look for a value using this:
var x = data.Find(a => a.ColumnD == [a value]);

Open in new window


But how can I store the values of one column in a list??

Thanks!
Avatar of YZlat
YZlat
Flag of United States of America image

What if you try

List<int> query = (from t in db.TABLE where t.RecordID == recordID 
                            group t by new { t.ColumnA, t.ColumnB,t.ColumnC }
                            into grp
                            select new { grp.ColumnD}).ToList<int>();

            return query;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of louisfr
louisfr

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of louisfr
louisfr

No reply from the author but the proposed solution should work.