【发布时间】:2011-06-26 14:09:46
【问题描述】:
我正在尝试查找用于BlogPost 的最受欢迎的Tags。
例如。
public class BlogPost
{
public int Id { get; set; }
public IEnumerable<string> Tags { get; set; }
}
所以我尝试了:
var tags = (from p in BlogPosts()
group bp by bp.Tags into g
select new {Tag = g.Key, Count = g.Count()})
.OrderByDescending(o => o.Count)
.Take(number);
但这不会编译。错误是:
Cannot implicitly convert type 'System.Linq.IQueryable<{Tag: System.IEnumerable<string>, Count: int}>' to 'System.Collections.Generic.Dictionary<string, int>'.
看看它是一个字符串列表吗?我希望浏览每篇博文中的每个标签,并计算出最受欢迎的标签。
【问题讨论】:
-
您收到的错误来自您发布的代码之外。能否给出报错的代码?