尝试根据某些输入值获取高分榜。数据库很旧并且集成在不同的地方,所以不能改变任何地方。
我得到了一个很好的有序列表,但是当我试图让用户与众不同时,它不再关心我的订单了。
我在请求数据时所做的事情是
这就是我所拥有的。
// Get current game based on id
var query = db.GameResult.Where(w => w.GameId == gameId);
// Get playes after
if(request.DateStart.HasValue)
{
query = query.Where(w => w.CreatedTime >= request.DateStart);
}
// Get playes before
if (request.DateEnd.HasValue)
{
query = query.Where(w => w.CreatedTime <= request.DateEnd);
}
// Score & created order by
if (request.SortScoreDesc && request.SortDateDesc)
{
query = query.OrderByDescending(o => o.Score).ThenByDescending(o => o.CreatedTime);
}
else if (!request.SortScoreDesc && !request.SortDateDesc)
{
query = query.OrderBy(o => o.Score).ThenBy(o => o.CreatedTime);
}
else if (!request.SortScoreDesc && request.SortDateDesc)
{
query = query.OrderBy(o => o.Score).ThenByDescending(o => o.CreatedTime);
}
else if (request.SortScoreDesc && !request.SortDateDesc)
{
query = query.OrderByDescending(o => o.Score).ThenBy(o => o.CreatedTime);
}
// Get unique users
if (request.Unique)
{
// CANNOT GET TO WORK
//query = query.GroupBy(o => o.Email).Select(r => r.FirstOrDefault());
}
query = query.Take(request.Rows);
List <GameResult> querylist = query.ToList();