score:15
Accepted answer
To sum your inner dictionary just do:
DictSum = pt.Select(x => x.UnitsSoldByYear.Values.Sum()).Sum()
or equally:
DictSum = pt.Sum(x => x.UnitsSoldByYear.Values.Sum())
EDIT:
according to the OP comment, this creates a dictionary with the sum by each key:
DictSum = pt.SelectMany(kvp => kvp.UnitsSoldByYear)
.GroupBy(kvp => kvp.Key)
.ToDictionary(grp => grp.Key,grp => grp.Sum(kvp => kvp.Value))
Source: stackoverflow.com
Related Articles
- How to make a SUM of Dictionary Value nested into a list with LINQ?
- LINQ - Convert List to Dictionary with Value as List
- LINQ querying nested dictionary with multiple key value selection in C#
- Return list with more than one value stored in a dictionary using linq
- Use LINQ to concatenate multiple rows list with same value into single row
- Can't add a new record with an integer value into database by using linq from code C#
- How to get list of keys in a dictionary with group by value with using LinQ
- C# Linq adding to dictionary with list as value
- Finding if value exists in list with LINQ and saving info into a dataset, possibly
- Creating a dictionary with LINQ and keys from nested list
- Dictionary lookup with LinQ to find a subset where the Value is a List element
- How to get nested key value pair from dictionary with linq
- Split List into Sublists with LINQ
- Merge multiple Lists into one List with LINQ
- Linq Query Dictionary where value in List
- C# LINQ - convert nested dictionary to a list
- How to implement SkipWhile with Linq to Sql without first loading the whole list into memory?
- List to Dictionary with incremental keys in one line LINQ statement
- LINQ on List with lot of nested List
- Nested LINQ query to select 'previous' value in a list
- Coercing a LINQ result list of KeyValuePair into a Dictionary - Missing the Concept
- Use linq expression to filter a dictionary with a list of keys
- Linq to Dictionary with key and a list
- Converting list with nested list to a separate list using Linq
- Combine object properties into a list with LINQ
- C# LINQ selecting a list with a property that has multiple value
- Transfor List to Nested Dictionary using linq C#
- C# Combine two lists with nested lists into one using LINQ
- Split list into two lists with single LINQ statement
- List to Dictionary with Group in Linq
- Left outer join with "and" in LINQ?
- c# ToDictionary with ContainsKey check
- Get Unique values from List<Dictionary<string, string>>
- LINQ Query for outerjoining Parent and child (nested) tables
- Calling methods from different Projects in one Solution
- Linq: how to select certain text "True" or "False" for corresponding boolean values?
- Unpack tuple in LINQ lambda
- Updating attributes of multiple input controls based on input value using Jquery LINQ
- entity framework to a list<>?
- SubmitChanges() immediately followed by a stored procedure
- linq after the join groupby and select
- compare two lists of differtent types using linq
- Join two IQueryable
- LINQ - C# - Using lambda - Get a set of data from a Collection
- Json children properties to dictionary
- LINQ to SQL for tables across databases. Or View?
- FirstOrDefault() throws Object reference not set to an instance of an object error
- LINQ queries give CS8600 and CS1662 warnings in VS2022 and C#10
- Compare 2 lists and provide new list with updated quanities
- SqlParameter is already contained by another SqlParameterCollection, but I don't see how