我有点问题,因为我试图GroupBy使用LINQ,虽然它的工作原理,它只适用于当我消除代码的一个元素。Linq Groupby的问题没有总结
nestedGroupedStocks = stkPositions.GroupBy(x => new { x.stockName,
x.stockLongshort,x.stockIsin, x.stockPrice })
.Select(y => new stockPos
{
stockName = y.Key.stockName,
stockLongshort = y.Key.stockLongshort,
stockIsin = y.Key.stockIsin,
stockPrice = y.Key.stockPrice,
stockQuantity = y.Sum(x => x.stockQuantity)
}).ToList();
上面的代码组我的股票仓位,并在含47项,但它不能做的是和重复的个股有不同批量的单子,结果...
nestedGroupedStocks = stkPositions.GroupBy(x => new { x.stockName,
x.stockIsin, x.stockPrice })
.Select(y => new stockPos
{
stockName = y.Key.stockName,
stockIsin = y.Key.stockIsin,
stockPrice = y.Key.stockPrice,
stockQuantity = y.Sum(x => x.stockQuantity)
}).ToList();
但是,如果我elimanate“x.longshort”然后我得到了想要的结果,34只个股总结出来的,但当时的列表中的所有longshort元素是空...
其驾驶我坚果:-)
发布你的清单数据 –