score:2
Accepted answer
I'm not sure how much I can guess correctly here, but let's give it a try.
First, let's assume, we may have this input:
var listOfOrders = new List<OrderItem>
{
new OrderItem
{
Id = 1,
OrderData = @"{
""orderLine1"": ""line1"",
""orderLine2"": ""line2"",
}",
OrderEvent = "Start",
OrderNo = 111
},
new OrderItem
{
Id = 1,
OrderData = @"{
""orderLine1"": ""line1"",
""orderLine2"": ""line2"",
}",
OrderEvent = "Start",
OrderNo = 111
},
new OrderItem
{
Id = 2,
OrderData = @"{
""orderLine1"": ""line1"",
""orderLine2"": ""line2"",
}",
OrderEvent = "Start",
OrderNo = 121
}
};
Now, I'm assuming you may want to group these items by OrderNo
and get a collection of items with the similar Order Number:
var collection = listOfOrders
.GroupBy(l => l.OrderNo)
.Select(group => new
{
Number = group.Key, // OrderNo
OrderEvent = group.Select(elm => new
{
OrderEvent = elm.OrderEvent,
OrderData = JObject.Parse(elm.OrderData) // assume we want to parse a
// JSON but this can be other logic
})
}).ToList();
Source: stackoverflow.com
Related Articles
- C# linq groupby including json
- LINQ Source Code Available
- LINQ Lambda efficiency of code groupby orderby
- creating Linq to sqlite dbml from DbLinq source code
- Linq GroupBy Clause not including items with zero count
- source code for LINQ 101 samples
- LINQ GroupBy Source = A Destination = B or Source = B and Destination = A
- Linq Code with Distinct or GroupBy not working
- c# Linq or code to extract groups from a single list of source data
- Deserializing JSON to .NET object using Newtonsoft (or LINQ to JSON maybe?)
- Convert string[] to int[] in one line of code using LINQ
- LINQ with groupby and count
- Code equivalent to the 'let' keyword in chained LINQ extension method calls
- Linq to Objects: does GroupBy preserve order of elements?
- Linq code to select one item
- How are people unit testing code that uses Linq to SQL
- C# Groupby Linq and foreach
- jqgrid with asp.net webmethod and json working with sorting, paging, searching and LINQ -- but needs dynamic operators
- GroupBy with linq method syntax (not query syntax)
- LINQ query to perform a projection, skipping or wrapping exceptions where source throws on IEnumerable.GetNext()
- How to select top N rows in a Linq GroupBy
- How to select last record in a LINQ GroupBy clause
- Translate SQL to lambda LINQ with GroupBy and Average
- Key comparisons for Linq GroupBy using Default EqualityComparer
- LINQ - GroupBy a key and then put each grouped item into separate 'buckets'
- Which is the best book out there to learn Linq, including Linq to Entities?
- Syntax to execute code block inside Linq query?
- How to use GroupBy using Dynamic LINQ
- writing a custom comparer for linq groupby
- Linq GroupBy with each null value as a group
- LINQ Query against Azure table service fails
- C# LINQ how to flatten parent list and two nested children lists into a new list
- Dynamic query with Linq
- How to query in LINQ & Entity Framework the unmapped property
- "unrecognized expression node array index linq" exception in LINQ to SQL
- How to parse XML file in c#
- EF Core Or Where clause with dynamic
- How to filter distinct data using linq
- Invalid Argument - Interfaces inherited, as works, implicit casting does not. What gives?
- How to use var more than once in linq?
- Read List<custom class> Containing Single Record
- Linq to object: ToList can not convert to generic list
- linq object equality and how to properly override it
- Add a if statement condition to a Linq statement
- Linq returning multiple values in a group by, need only last modified
- Trying to concatenate LINQ column values, Not sure where the LINQ error is?
- date difference with linq
- LINQ expression to get child records with unique parent
- Convert iDictionary<TKey,TValue> into IDictionary<TSomeProperty, ICollection<TValue>>
- Linq to SQL Slow Query