score:1
Accepted answer
var result = list.groupby(x => new { x.categorycode, x.categoryname })
.select(x => new
{
x.key.categorycode,
x.key.categoryname,
merchants = x.tolist().groupby(g => new { g.merchantid, g.mechantname })
.select(v => new
{
v.key.merchantid,
v.key.mechantname,
vouchers = v.select(s => new { id = s.voucherid, description = s.voucherdescription })
.tolist()
})
});
var json = jsonconvert.serializeobject(result);
Source: stackoverflow.com
Related Query
- How to get a nested json result after grouping a list?
- Get values from Grouping result except values from list
- Linq to NHibernate: how to get a list of child objects without having the lists nested
- How to GroupBy by result of async Task<string> method and get a grouping by string in C#?
- Get a list from a dynamic json result
- How to get the very next element from the list after finding the key element
- How do I get Age distribution list by grouping
- How to convert a list of anonymous object to string array using linq for return using Json Result in ASP.NET MVC
- How to get the value by a key from a super nested Json
- How to get a child nested list within a record using EFCore Linq
- How to get records if only all of the list elements included in nested collections?
- How to get list of data from foreign key associated table is json format in mvc
- How to get top 4 result from a list using linq c#
- How to get the sum of a list after I grouped it
- How to get list from nested list with highest length?
- LINQ: how to aggregate list within object after grouping properties
- Linq: How can I get a result in a grouping query which is value agnostic and has dynamic columns?
- How do I get a list of distinct rows from the result of multiple joins in Linq?
- How to get an IDS list of a Json type object with LINQ
- How do I get a list of all properties including those within nested objects within a class file
- How do I get value from a nested list with reflection?
- How to get name data of multiple json object list that will be posted to web api?
- How can I get the index of an item in a list in a single step?
- How to get duplicate items from a list using LINQ?
- How do I get a distinct, ordered list of names from a DataTable using LINQ?
- How to get a distinct list from a List of objects?
- LINQ: How to get items from an inner list into one list?
- How to get distinct instance from a list by Lambda or LINQ
- How to query a nested list using a lambda expression
- How to get a list of the grouped values in linq groupby?
More Query from same tag
- Why does IQueryable.Select use the same reference for each iteration
- Is there a way to combine these two LINQ statements into one
- Any way to make this LINQ faster?
- Calculate sum of column using group by in Linq
- Dynamic Linq with IN List
- Proper Searching with Linq, Entity Framework and Database Indexes
- Query items inside collection inside collection
- Update specific value in JSON file
- How to check comma separated values stored in data base column having the given value using linq in c#
- linq marge duplicate values
- Using a model to create a drop down list
- Slowness when chaining LINQ queries
- Is there a better way of calling LINQ Any + NOT All?
- Why does a variable value have to be modelled as a member access to the closure in an expression tree?
- Linq Contains check on string had mis-detect
- Use of anonymous in LINQ
- Replacing values lower than threshold using LINQ
- Implement a Discover page with friends of friends
- LINQ to Entities does not recognize the method 'System.String ToString()' method and this method cannot be translated into a store expression
- Entity Framework returns null object when row has null values
- In EF6, how to create a generic method to get entities using a common field/column
- Modeling a tree-like structure in db with EF
- Why does IEnumerable.Where method allow a predicate that can change the data?
- Linq in C++ CLI
- Flatten IEnumerable in EFcore using linq
- Removing elements from binding list
- LINQ assistance
- Insert element with LINQ
- C# - Help with LINQ
- Xpath expression to LINQ expression