我的数据库中有两个表,如下所示:
用户:
userid(int)
username(varchar)
分数:
scoreid(int)
result(bit)
attackinguserid(int) (same as User.userid)
它们还包含其他信息,但现在这并不重要。我想要的是获得 score = true 的前 25 名用户并像这样显示它们:
Username: Won:
Peter 28
Mike 25
Kim 20
等等......我一直在尝试的代码是这样的:
var winners = (from s in dc.Scores
from u in dc.Users
where (s.result) && (s.attackinguserid == u.userid)
group u by s
into groups
select new
{
Username= groups.Key,
Won= groups.Count()
}
).OrderByDescending(x => x.Seire).Distinct().Take(25);
gvBestPlayers.DataSource = winners; //gvBestPlayers = gridview
gvBestPlayers.DataBind();
但这给了我在 DataBind() 上的错误。错误:NotSupportedException 未被用户代码处理。成员“System.Web.UI.Page.Title”不支持 SQL 转换。