C# 检索三列并按一列分组

C# 检索三列并按一列分组,c#,arrays,linq,C#,Arrays,Linq,我有一个由不同列组成的SQL表,对应于角色数据(在游戏中)在这些列中,我想取级别、日期(即数据放在表中的时间),然后是与字符脚本相对应的字符串简言之,我需要一个字典,或者一个可选的(当然是c#中的)脚本作为键,在一个KeyValuePair列表(可能?)中使用 例如,类似这样的东西:(它不是json,我只是表示我想要的东西) 这是为了计算平均水平,并将此列表转换为Json以在google图表上绘制图表 这里是我尝试的一个例子,但它根本不起作用,哈哈 Dictionary<string, T


我有一个由不同列组成的SQL表,对应于角色数据(在游戏中)
在这些列中,我想取级别、日期(即数据放在表中的时间),然后是与字符脚本相对应的字符串

简言之,我需要一个字典,或者一个可选的(当然是c#中的)脚本作为键,在一个KeyValuePair列表(可能?)中使用

例如,类似这样的东西:(它不是json,我只是表示我想要的东西)

这是为了计算平均水平,并将此列表转换为Json以在google图表上绘制图表

这里是我尝试的一个例子,但它根本不起作用,哈哈

Dictionary<string, Tuple<int, DateTime>> lvlList = archivedCharacterList.Select(i => new { i.Level, i.Updated_at, i.Script_Name })
                                                                                                   .GroupBy(c => c.Script_Name)
                                                                                                   .OrderBy(g => g.Key.Updated_at)
                                                                                                   .ToList();
Dictionary lvlList=archivedCharacterList.Select(i=>new{i.Level,i.Updated\u at,i.Script\u Name})
.GroupBy(c=>c.Script\u名称)
.OrderBy(g=>g.Key.Updated_at)
.ToList();
谢谢你抽出时间


更新(解决方案):
感谢@StriplingWarrior

 ILookup<string, (int, DateTime)> lvlList = archivedCharacterList
   .Select(i => new { i.Level, i.Updated_at, i.Script_Name })
   .OrderBy(g => g.Updated_at)
   .ToLookup(c => c.Script_Name, c => (c.Level, c.Updated_at)); 

    foreach (var line in lvlList)
     {
         Console.WriteLine(line.Key); // Script 
         foreach ((byte, DateTime) items in line)
         Console.WriteLine("{0} {1}", items.Item1, items.Item2);
     }
// Then I just have to add this to what I want :)
ILookup lvlList=archivedCharacterList
.Select(i=>new{i.Level,i.Updated\u at,i.Script\u Name})
.OrderBy(g=>g.Updated\u at)
.ToLookup(c=>c.Script_Name,c=>(c.Level,c.Updated_at));
foreach(lvlList中的var行)
{
Console.WriteLine(line.Key);//脚本
foreach((字节,日期时间)行中的项)
WriteLine(“{0}{1}”,items.Item1,items.Item2);
}
//然后,我只需将此添加到我想要的内容中:)

这很好

您需要一个
ILookup
(如果您需要能够按索引进行查找)

ILookup lvlList=archivedCharacterList
.Select(i=>new{i.Level,i.Updated\u at,i.Script\u Name})
.OrderBy(g=>g.Updated\u at)
.ToLookup(c=>c.Script_Name,c=>(c.Level,c.Updated_at));

您可以共享archivedCharacterList中项目的类型定义吗?级别为int,更新时间为DateTime,脚本为string请发布表格的“创建表格”语句,并发布一些示例源数据(到目前为止,您只发布了示例输出数据)
 ILookup<string, (int, DateTime)> lvlList = archivedCharacterList
   .Select(i => new { i.Level, i.Updated_at, i.Script_Name })
   .OrderBy(g => g.Updated_at)
   .ToLookup(c => c.Script_Name, c => (c.Level, c.Updated_at)); 

    foreach (var line in lvlList)
     {
         Console.WriteLine(line.Key); // Script 
         foreach ((byte, DateTime) items in line)
         Console.WriteLine("{0} {1}", items.Item1, items.Item2);
     }
// Then I just have to add this to what I want :)
ILookup<string, (int, DateTime)> lvlList = archivedCharacterList
    .Select(i => new { i.Level, i.Updated_at, i.Script_Name })
    .OrderBy(g => g.Updated_at)
    .ToLookup(c => c.Script_Name, c => (c.Level, c.Updated_at));