0
データモデルとそれらを移入することは、このようなものです:ネストされた辞書を使用してLINQクエリ
public class UserInfo
{
public string UserName { get; set; }
public int GameId { get; set; }
public int Score { get; set; }
}
public class Game
{
public int Id { get; set; }
public int TypeId { get; set; }
}
public class Type
{
public int Id { get; set; }
//and many other things
}
は私がしたいことは、そのゲームにおけるユーザーのランクを示し、すべてのゲーム内のすべてのユーザの順番を持つことです。私は毎日更新されます。このため、データをキャッシュしたい
、私がこれまで行ってきたことはこれです:
class Class1
{
private readonly IDictionary<int, IDictionary<int, IDictionary<string, int>>> _scoreDictionary =
new ConcurrentDictionary<int, IDictionary<int, IDictionary<string, int>>>();
private readonly object _scoreDictionaryLock = new object();
private void InitializeDctionary(int typeId, IList<Game> gameInformations, IList<UserInfo> userInformations)
{
if (!_scoreDictionary.ContainsKey(typeId))
{
lock (_scoreDictionaryLock)
{
foreach (var gameInformation in gameInformations)
{
var orderdUsers = userInformations.Where(s => s.GameId ==gameInformation.Id).OrderByDescending(s => s.Score).Select((value, index) => new
{
value,
index//this is the user rank
}).Select(p => new
{
p.value.UserName,
p.index
}).Select(p=>new KeyValuePair<string,int>(p.UserName,p.index));
}
// I don't know what to do I want a dictionary that in first level key be typeId and then gameId then userName the final value is user rank.
_scoreDictionary.Add(typeId,???????????);
}
}
}
}
いくつかの変更を加えると、tnx – someone