Questions tagged [linq-group]
139 questions
1
vote
1 answer
linq, group by and count
I have a list of Unions with several members and another table with page hits by Union.
Need a report that list each union, the number of each type of member and the clicks (page views).
clicks are on a separate table with a date and unionID
this is…

Hector
- 11
- 1
- 2
1
vote
1 answer
How could I LINQ's GroupBy() with a boundary?
Let's say I have a collection of elements which have a float property.
I was grouping by it but I found I was getting undesired groupings.
For example (with a double to take profit of Random's NextDouble()):
void Main()
{
var examples = new…

Gonzo345
- 1,133
- 3
- 20
- 42
1
vote
2 answers
Linq Groupby Elapsed Time
I need to group by a list by owner, town and "timeout".
I will explain "timeout":
public class Ticket
{
public int pk { get; set; }
public string owner { get; set; }
public string reffering { get; set; }
public DateTime? created_time…

karim harfakti
- 13
- 4
1
vote
2 answers
C# Code Optimization GroupBy
I have a couple of problems with my below code.
var groupedItems = inputFiles.GroupBy(q => q.Name.ToLower().Split('_').ElementAt(2));
string currentNo = ////value retreived from someMethod;
if (string.IsNullOrEmpty(currentNo))
…

KeenUser
- 5,305
- 14
- 41
- 62
1
vote
2 answers
Simplest way to perform grouping/projection using Linq To Objects
I'm getting data from the data layer that I need to transform in the middle tier using Linq To Objects (I don't control that tier of the application). I have to perform a grouping operation using multiple keys followed by a string concatenation on…

Mitch A
- 2,050
- 1
- 21
- 41
1
vote
1 answer
Linq group with sum function and nested records
There is a collection:
List> sales = new List> {
Tuple.Create("Store 1", "Product 1", 1000),
Tuple.Create("Store 2", "Product 2", 2000),
Tuple.Create("Store…

user2134488
- 451
- 5
- 13
1
vote
3 answers
Linq to dataset select row based on max value of column
I have a dataset table, I want to group it by column MOID, and then within this group I want to select the row which has max value of column radi.
Can anybody show me how to do it via LINQ to dataset?

user424493
- 51
- 1
- 4
1
vote
1 answer
Group and sum List
I have raw list in C# (RoomId,WallTypeId,WallTypeArea) which I need to group by the two first, then sum the third. For each room and walltype I need an area. (How much walltype in each room.) It can be done simple with a couple of foreach loops I…

Håvard Dagsvik
- 11
- 2
1
vote
2 answers
Linq Grouping - aggregate, outside of a group by
I've got a SQL query, that works as follows:
SELECT TOP 100
Max(Table_ID) as Max_ID,
Col1,
Col2,
Col3,
COUNT(*) AS Occurences
FROM myTable
GROUP BY Col1, Col2, Col3
ORDER BY Occurences DESC
How can I write an identical Linq query?
The issue…

Dave Bish
- 19,263
- 7
- 46
- 63
1
vote
1 answer
Linq group outer joins projected on a viewmodel
I have been scouting the internet for the past 2 days to find a solution to grouping the below linq query on BookId to no avail. The query works but I want to reoganise it so that It can group on BookId or BookTitle.
models
Book(BookId, Title,…

Diin
- 565
- 11
- 41
1
vote
2 answers
how to group by one column only using linq?
I am using a Linq query to group a column (string of Phones) and return that column and the last value of a second column called Status (also a string of numbers). I want to add the result of this query to a new dataTable.
I've tried it in many…

Talkat
- 13
- 4
1
vote
1 answer
How do I get a count of values by month in linq to sql?
I have a table of feedback scores, which essentially contains a date field and a "score" field (which may be "happy", "neutral" or "sad").
I want to return a query which gives me the count of each score by month, like this:
However, my query isn't…

Ben
- 4,281
- 8
- 62
- 103
1
vote
2 answers
How to group a list of grouped lists?
I need a grouped list of grouped lists; I have a bunch of articles that I need to group by year, and group by month within each year. It will look something like this on the page:
2015
February
Article 1 Title
Article 2 Title
January
Article 3…

Erica Stockwell-Alpert
- 4,624
- 10
- 63
- 130
1
vote
1 answer
Take Last n Items from a Grouped and Ordered List using Entity Framework
I have a list of Forms, and in this list the forms with the same Title denotes the different version of the that form, the one with closest Creation Time (which is DateTime type) is newer version.
So I want to select each forms last n versions using…

Sarge
- 388
- 1
- 4
- 22
1
vote
1 answer
Getting linq error with group
I am getting the following error when I add the linq grouping.
Error 5 'System.Linq.IGrouping' does not contain a definition for 'Description' and no extension method 'Description' accepting a first argument of type 'System.Linq.IGrouping' could…

Dwight T
- 1,457
- 2
- 11
- 20