linq을 사용하여 GroupBy를 사용하려고하는데 문제가 있습니다. 작동하지만 코드의 한 요소 만 제거하면 작동합니다.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();
나는 경우 나에게 견과류 :-) 운전 "x.longshort"그럼 내가 원하는 결과, 34 개 주식 요약 얻을하지만, 목록에있는 모든 longshort 요소가 null입니다 ...
그것을 elimanate
목록 데이터 제출 –