Questions tagged [linq-group]
139 questions
0
votes
1 answer
Join elements in a list of objects
I have this class:
public class Note
{
public DateTime Date { get; set; }
public string Time { get; set; }
public string Text { get; set; }
}
and a list
List ungroupedNotes;
What I want to do is group multiple notes that have…

Cătălin Rădoi
- 1,804
- 23
- 43
0
votes
1 answer
LINQ nested grouping with multiple collections
I am currently struggling to assemble a LINQ query on my objects collections : Persons, Cars
Each person can have multiple cars.
I want to select all PERSONS in persons and all group all cars owned by this person. The query I have written so far…

Jas Sra
- 3
- 1
- 5
0
votes
1 answer
Grouping resulting in anonymous types
I have a list of strings such as this one
heading1 00:01:20
randomText
01:23
randomText2
01:45
randomText3
02:10
heading2 00:05:20
randomText4
07:25
randomText5
04:35
randomText6
09:12
etc.
What I'd like to do is using Linq to get a list of…

Louitbol
- 170
- 1
- 16
0
votes
1 answer
Does a Linq expression treat a group specially when iterating it with the 'from' clause?
Consider this query to group a list of students by the 1st letter of their last name:
var query = from s in students
group s by s.Last[0] into group1
orderby group1.Key
from g in group1
select new {…

Jules
- 4,319
- 3
- 44
- 72
0
votes
1 answer
Linq and grouping with three tables
I've come up with the following LINQ, but I can't help thinking that I should be able to do this in one query instead of two. Can anyone help?
The idea is to inner join three tables and group by one.
var q1 = from er in ExportRules
join per in…

David Hyde
- 902
- 9
- 18
0
votes
1 answer
Linq joins and groups
Following on from my previous question: Simple inner join in linq
How would I write some linq to do exactly the same as the below..
SELECT A.name, B.name
FROM A
INNER JOIN B ON A.id = B.AID
INNER JOIN C ON B.id = C.BID
GROUP BY A.Name, B.Name
ORDER…

Jon
- 85
- 1
- 8
0
votes
2 answers
LinQ Group.Average truncates my values
I've the following table structure:
tempDt
col1 = Product (Integer)
col2 = Customer (Integer)
col3 = Center (Integer)
col4 = Date (Date)
col5 = Price (Double)
col6 = Sales (Double)
This example rows:
1;1;1;01.01.2012;4.39;20000 …

user1434532
- 57
- 1
- 8
-1
votes
1 answer
C# Group items on multiple values and keep null values as partial matches
I have a list of items that need to be grouped on 3 fields. However, I need to include items in a group if some of these fields are null, but the rest match. It's kind of hard to explain, but here is a scenario.
So for example, we have a list of the…

wingthor
- 54
- 1
- 3
-1
votes
2 answers
C# group by a list contains another class
I have two classes as below:
public class result
{
public person identity { get; set; }
}
public class person
{
public string name { get; set; }
public string family { get; set; }
}
I have List which has some repetitive data.…

Amirali Sam
- 387
- 9
- 21
-1
votes
2 answers
How to get all the fields after groupby in LINQ
I have this object
With Fecha="Julio2017" I have 2 items and I need to group these three items by SubcontratistaId and Fecha.
item1.Realizado=4060.000 and item2.Realizado=-4060.000 So I need to show in Julio2017 the value of 0
So I try…

kintela
- 1,283
- 1
- 14
- 32
-1
votes
2 answers
Grouping and collect nested object with C# Linq
happy coding.
I can group and sum with linq but this is a bit different. I want to group the elements and gather them one by one. I wanna group by TaxTypeCode and collect TaxAmount values.
I'm sorry it's such a long question.
My xml
…

arthur
- 85
- 7
-1
votes
1 answer
HOW TO query with linq GROUP BY multiple and SELECT
I already have the following code.
But i dont know whats wrong. Why cant i do the group by with the select?
Any idea?
thanks!
lstPendientes = await (from item in db.erProcesaReenvio
group item by new
{
…

dlerma
- 49
- 1
- 5
-1
votes
2 answers
Where is the mistake? Group by, join , select .net
I don´t know where is the mistake why it says that does not contain a defintion of ImporteSolicitado, interesesDemora and importeReintegro when they are colums of c and the last one of d
var importes = (from c in _context.ReintegroSolicitado
…
-1
votes
1 answer
Linq group query gives wrong results
I have some problems in executing a Linq query with the group by clause in a C# project as follows:
public class Stock {
public string Name {get; set;}
public List Values {get; set;}
public float Price {get; set;}
}
// Stock…

murtzi
- 11
- 2
-1
votes
1 answer
Distinct IList and select second element
I have an IList collection
public IList Items
I can group that list and take first element of each group
Items.GroupBy(x => x.Type).Select(grp => grp.First()).ToList();
How can I group that list and take not first element (for example:…

Armen Mkrtchyan
- 921
- 1
- 13
- 34