Return List<string> after group by
I have a function
p开发者_如何学Pythonublic 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>
?
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 :)
精彩评论