我想将下面的pivot函数的结果提取到csv V文件中。 有没有人知道如何以更通用的方式完成这一点,而不必写太多 手动代码?在这个阶段,coulmn的名字并不重要,但是如果也可以通过从预先加载的数组或列表等中读取来动态设置...
非常感谢提前 M
public static Dictionary<TKey1, Dictionary<TKey2,Dictionary<TKey3,Dictionary<TKey4,TValue>>>> PivotLinq<TSource, TKey1, TKey2,TKey3,TKey4, TValue>(
this IEnumerable<TSource> source, Func<TSource, TKey1> key1Selector, Func<TSource, TKey2> key2Selector, Func<TSource, TKey3> key3Selector, Func<TSource, TKey4> key4Selector,
Func<IEnumerable<TSource>, TValue> aggregate)
{
return source.GroupBy(key1Selector).Select(
x => new
{
X = x.Key,
Y = x.GroupBy(key2Selector).Select(
z => new
{
Z = z.Key,
V =z.GroupBy(key3Selector).Select(
w => new
{
W=w.Key ,
B = w.GroupBy(key4Selector).Select(
c=> new
{
C=c.Key ,
D=aggregate(c)
}).ToDictionary(e=>e.C, o=>o.D)
}
).ToDictionary(e=>e.W, o=>o.B)
}
).ToDictionary(e=>e.Z , o=>o.V )
}).ToDictionary(e=>e.X,o=>o.Y);
}