2

I have a function

public List<string> UserList()
{
    var q = from i in _dataContext.PageStat group i by new { i.UserName } into ii select new { ii.Key.UserName };
}

How can I return List<string>?

ekad
  • 14,436
  • 26
  • 44
  • 46
kusanagi
  • 14,296
  • 20
  • 86
  • 111
  • possible duplicate of [return a single list property List in Linq](http://stackoverflow.com/questions/2835830/return-a-single-list-property-list-in-linq) – Gabe Jul 03 '10 at 10:28

1 Answers1

6

It looks like you just want the distinct set of usernames... why not just use:

return _dataContext.PageStat.Select(u => u.UserName)
                            .Distinct()
                            .ToList();

If you really want to use grouping, you could do:

var q = from i in _dataContext.PageStat
        group i by i.UserName into ii
        select ii.Key;
return q.ToList();

You don't need all those anonymous types :)

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194