score:5
Accepted answer
not linq syntax, but at least more elegant...
list<note> mergednotes =
notes
.groupby(x => x.userid)
.selectmany(g => getmergednotesfor(g.orderby(x => x.createdon)))
.tolist();
with my test data it creates the same result as your original code.
score:5
i think this does the trick:
var mergednotes = new list<note>();
mergednotes.addrange((from n in notes
orderby n.createdon
group n by n.userid into g
let m = getmergednotesfor(g)
select m).selectmany(m => m));
return mergednotes;
Source: stackoverflow.com
Related Query
- How can I write the following code more elegantly using LINQ query syntax?
- How can we express the following code using query expression?
- How can I check the number of calls to the database in LINQ query when using .NET Core and Code First?
- How can I simplify (speed up) the selecting query from a database that contains more than 1 million records using LINQ
- How to write this code using the Linq Extension Method-Syntax?
- How Can I Write a LINQ Query to Get Content Within the Last Seven Days?
- How can I write the "Where" clause in the following LINQ to SQL Query?
- How can i change the following LINQ query as normal sql query
- How to write aggregate query in LINQ reusing part of the select code
- How do I write a LINQ query which will generate a JSON string with the following format?
- How can I condense the following Linq query into one IQueryable
- How to write the following query in LINQ
- I have a LINQ statement that is partially query and partially method. How can I do this using one or the other?
- how to write the following in LINQ syntax
- How can I convert my LINQ query to use the lambda syntax and is there any advantage to doing this?
- How can I write a LINQ query towards a table in the Local Storage Account?
- How can I write the nested linq query
- how I can have the following value using Linq
- How can I filter a dictionary using LINQ and return it to a dictionary from the same type
- How can I write Take(1) in query syntax
- How to Convert LINQ Comprehension Query Syntax to Method Syntax using Lambda
- How can I trace the query produced by the documentdb Linq provider?
- How to understand the following C# linq code of implementing the algorithm to return all combinations of k elements from n
- When using a LINQ Where clause on a Dictionary, how can I return a dictionary of the same type?
- How can I view the Entity Framework LINQ query plan cache?
- How can I implement a LEFT OUTER JOIN in LINQ using lambda syntax on Entity Framework Core 2.0?
- How can I code an outer join using LINQ and EF6?
- How do I write a LINQ query that inverts the grouping of a hierarchical data source?
- How to use expressions to build a LINQ query dynamically when using an interface to get the column name?
- How to do the following in Dynamic Linq using System.Linq.Dynamic namespace
More Query from same tag
- Entity Framework - select data
- How to convert this LINQ query from methods form to fluent syntax?
- LINQ building array with multiple values per select
- Linq to XML pulling back an attribute that exists on a different level
- Entity Framework ThenInclude filtered from original dataset
- NHibernate 3 GA LINQ with new Fluent NHbernate binaries boolean conversion issue
- Return one column from navigation table in my lambda linq query by .include()
- Most efficient way to find a "space" in an ordered list using LINQ
- C# WebApi refactoring Select Linq
- Avoiding duplicate code in Linq Select method
- LINQ Equivalent of SELECT DISTINCT
- Linq Query Failed with Concat Operator
- Extract filtered list from large list
- Linq group by specific property of a class and then take min and max value
- What should be the return type when writing Linq query for selecting specific columns?
- Using LINQ to find duplicates across multiple properties
- Concat arrays at a certain index with LINQ?
- Use LINQ to check if all values are "0"?
- How to use orderby with 2 fields in linq?
- Combine Multiple Linq Expressions
- How do I implement a search feature with Entity Framework?
- Using LINQ to return average of distinct values
- left join with linq how to
- LINQ operater Where not supporting any of the members when used inside generic method
- Concatenation of measurements in SQL Database with Linq
- Linq group by element and a sub element
- C# Linq combine multiple values into data row
- Handle Nullable bool in linq query
- Specific value with linq
- Filter Both Parent And Child Collection