score:8
Accepted answer
you can do that with a selectmany
.
var list = dictionary.selectmany(
kvp => kvp.value,
(kvp,obj) => new {obj.property0, obj.property1, obj.property2, kvp.key})
.tolist();
or in query snytax
var list = (from kvp in dictionary
from obj in kvp.value
select new {obj.property0, obj.property1, obj.property2, kvp.key})
.tolist();
note this results in a list of an anonymous class. if you really want dynamic
you'll need to do a cast<dynamic>()
before the tolist()
. also if you want the last property of the anonymous class to be key
instead of key
you'll need to do key = kvp.key
.
Source: stackoverflow.com
Related Query
- How to convert Dictionary to List with mixing of values and keys?
- How to extract values from a list of dictionaries and group and convert to a single dictionary with Linq?
- How do I combine the keys and values of a Dictionary into one List using LINQ?
- List of objects to Dictionary with distinct keys and selected values
- Compare keys of dictionary with values of List and return all the matching values including duplicates
- LINQ: Getting Keys for a given list of Values from Dictionary and vice versa
- Convert a list to a dictionary and sum up values using linq
- Search dictionary values and return List of keys meeting conditions
- LINQ: Given A List of Objects, Create a Dictionary with child objects as keys and Parent Objects as Value
- How do I join an array of keys with an array of values to a dictionary without a loop?
- How to convert dictionary with object to list of that type?
- Linq "group by" values in a Dictionary property with a list of keys
- How to filter list of dictionary values with criteria
- How to get list of keys in a dictionary with group by value with using LinQ
- How to find keys in a Dict<int,List<Tuple<string,string>>> such that the list contains elements with given Item1 and Items
- How to bind and save an object containing a list of objects to database context in ASP.NET MVC with EF code first?
- Group dictionary by values and return list of keys
- Get keys (objects) from a dictionary that contains list and filtered by values
- How to iterate in a list to find names and values with linq
- How to convert Dictionary <string,List<string>> in C# to csv with keys as headers?
- How do I left join a string List and fill in missing values with zeros
- How to populate a dictionary from another with same keys but values cumulated
- How to iterate through a list and while iterating, iterate through another list and replace values for upper list with inner list key value pairs
- Creating a dictionary with LINQ and keys from nested list
- How to consolidate a Dictionary with multiple (three) keys by reducing one or more key and merging the multiple records (if any) into one single one?
- How can I flatten a dictionary of dictionaries and sum the values of the inner dictionary with LINQ?
- Dicionary intersect keys with list and get in result dicionary with values at the beggining LINQ
- Convert list to dictionary using linq and not worrying about duplicates
- LINQ - Convert List to Dictionary with Value as List
- What does this C# code with an "arrow" mean and how is it called?
More Query from same tag
- Why removing objects from a list with duplicate properties of types double in C# does not give consistent result using different methods?
- C# generic function applicable on Linq objects in a json server application
- Rename List item when there is the same string multiple time
- LINQ analogues in Scala?
- How to get all the values from an SQL Query C#
- LINQ - Sort by StartsWith and then Contains (AutoComplete)
- how do I compare values from List using simple Odata filter?
- Linq RemoveFirst equivalent
- How to query multiple tables using LINQ syntax in .NET core 3
- Traversing ASP.NET HTML Elements using LINQ
- Obtaining the outcome of a LINQ Select Query and assigning it to a string
- Using Linq to GroupBy and Case When via datatable
- Loading nested relationships using Entity Framework
- Json does not go to next or previous text when clicking on button with using Linq in C#
- Is it possible to get other collection than IEnumerable<T> when using LINQ: XML to object?
- Calling Enumerable.Join on a IEnumerable collection causes segmentation fault
- Excluding items from a list that exist in another list
- Entity Framework Error - The cast to value type 'System.Int64' failed because the materialized value is null
- C# Linq and Regexing non-unicode
- Manipulating data in a collection with LINQ
- Split string at specific character but ignore some cases C# LINQ
- Dynamic linq query with join
- Unable to create instance of MyEntities
- How to compare previous record column value with current record column value of a list using LINQ query in C#
- C# LINQ Query with group by, having and where clause invalid
- Difficulty with Linq on inner and left outer joins
- Simple Linq Dynamic Query question
- List<T>.RemoveAll as parallel
- How to handle IEnumerable with IGrouping in the view?
- C# Linq Join Lambda (a key selector contains the other key selector)