score:2
Accepted answer
Generally speaking, you need different queries for this. The same goes for building up different WHERE
or Where(...)
clauses based on user selection:
var query = OrderQuery;
if (userSelection == "GroupByName") {
query = from to in query
group to by to.FromDateUtc into groupedDate
let grouped = groupedDate.GroupBy(o => o.Name);
}
else if (userSelection == "GroupBySomethingElse") {
query = from to in query
group to by to.FromDateUtc into groupedDate
let grouped = groupedDate.GroupBy(o => o.SomethingElse);
}
You'll want to prepare as much common logic as possible before you apply the grouping to query
. Because LINQ uses deferred execution you can modify query
as much as you need before enumerating the result and you will not incur a performance hit.
score:0
If you are trying to do something like this
SELECT * FROM <TableName> GROUP BY <Column1>,<Column2>
Then, take a look at this post
Source: stackoverflow.com
Related Articles
- Linq - SQL passing parameters into GroupBy()
- Passing null parameters into LINQ where clause
- LINQ - GroupBy a key and then put each grouped item into separate 'buckets'
- Why does LINQ to SQL translate GroupBy into multiple queries
- Passing some of a LINQ query into an argument of a function?
- LINQ Source Code Available
- How can I combine this code into one or two LINQ queries?
- add dynamic anonymous object into linq groupBy expression
- LINQ Lambda efficiency of code groupby orderby
- How to get SQL query into LINQ form in C# code
- Passing LINQ expressions as parameters
- creating Linq to sqlite dbml from DbLinq source code
- Using LINQ with MVC, how can I include multiple parameters into a where clause?
- Linq Group By Into with additional parameters
- Passing a list<string> into Linq
- Linq GroupBy into new object
- How to flatten a multi level XML into a single level XML using c# code LINQ
- Convert piece of code into LINQ (short syntax)
- Can't add a new record with an integer value into database by using linq from code C#
- How can I code numerous MIN functions into one LINQ to DataSet query
- Injecting Code Into Linq
- Can I can convert this C# code into some Linq code?
- Translating Linq Code Block into SQL
- LINQ - GroupBy a key of paired object, then separate the grouped object into list of 2 objects?
- source code for LINQ 101 samples
- query entity with linq passing in two parameters
- LINQ GroupBy into a new object
- How to combine 2 linq statments with groupby clause into 1
- LINQ GroupBy Source = A Destination = B or Source = B and Destination = A
- LINQ GroupBy with multiple dynamic complex parameters
- Save data with foreign key or roll back if any fail
- Converting a SQL to Linq Query
- how to make group by and orderby linq
- LINQ query to return whether an item is found in an array?
- MVC3 HtmlHelpers using Generics and LINQ
- Anglesharp - How to get ratings & reviews from a Yelp site?
- Compare two lists, item by item, using linq
- how to find correct model item from list
- C# linq query rank by two conditions
- How to search List<T> with user input string?
- Parsing XML Data with LINQ
- How do you convert SQL to LINQ
- Join Table Group By Summary On Linq
- Get values from list that match BOTH attributes using c# LINQ
- How can i return null for a json property instead of "data": []
- get an item of a list in a list
- Get previous day data from database based on frequently changing date on button click
- Using Linq to get maximum value of only duplicates
- CS0266 Cannot implicitly convert type 'System.Collections.Generic.List<System.Linq.IGrouping to 'System.Collections.Generic.List'
- Unable to translate SQL query to LINQ using EF