Questions tagged [igrouping]

The .NET interface for a collection of objects with a common key

The IGrouping interface, introduced in as part of , represents "a collection of objects with a common key".

It is typically encountered as a result of a GroupBy operation - for example

IGrouping<System.Reflection.MemberTypes, System.Reflection.MemberInfo> group =
    typeof(String).GetMembers().
    GroupBy(member => member.MemberType).
    First();

The members of the interface are used when handling results of any GroupBy operation. Questions that deal with handling the results of such GroupBy operations, or which otherwise construct objects that implement this interface, are expected to have this tag.

The interface itself defines available methods and properties which generally involve working with the objects inside the collection (or group).

76 questions
1
vote
0 answers

IGrouping implementation and null keys

I'm converting code in preparation to C#9, in particular the below class implementing IGrouping: public class Grouping : IGrouping { public TKey Key { get; } public Grouping(TKey key,…
vc 74
  • 37,131
  • 7
  • 73
  • 89
1
vote
1 answer

How can interface IGrouping yield multiple values?

I wonder what point I overlook. IGrouping is used by LINQ GroupBy. Further, the same logic is applied to ILookup, IIRC. Accordingly, they can return multiple values subject to the key specified. However, instead, I would…
1
vote
1 answer

Why do I get duplicate keys as using groupby LINQ

I'm using the following snippet to catch all debts belonging to a customer belonged to an account number which is unique. However, I get duplicates of the account numbers even I have chosen it as the key. I'm too amazed. var records =…
1
vote
2 answers

IGrouping.ToList() - Handling null values

I have a simple one-line linq query to find items in a list which contain the highest property value, and create a new list with them only if there are a certain count of items that match this criteria. For example: List objects = new…
devklick
  • 2,000
  • 3
  • 30
  • 47
1
vote
2 answers

Group by using the Entity Framework

I receive 48 files per day on a half hourly basis from market. These files have a start time as a property. I am using Entity Framework to view these files in a web application and as the files have a UK time but I am working with a european market…
Jay
  • 3,012
  • 14
  • 48
  • 99
1
vote
4 answers

How to concat to IEnumerable IGrouping?

I have two IEnumerable IGrouping in my C# program: IEnumerable> number1 IEnumerable> number2 Is it somehow possible to concat these two IEnumerable into one?
user2672399
  • 185
  • 1
  • 10
1
vote
0 answers

How to groupby an IGroupable double? List<> within an interval range

So far I have grouped an IQueryable of results into distinct groups based on 1 double property, the double being a theoretical total, for example: IGrouping>() 1.2, 1.5, 2.1, 3.6, 3.7, 3.8, 4.0, 4.5, 5.6, 5.7 …
d_unique
  • 21
  • 1
  • 3
1
vote
1 answer

Replace the Key of an IGrouping?

Is it possible to replace the Key by which an IGrouping is grouped? I'm currently grouping by an anonymous type like this: var groups = orders.GroupBy(o => new { o.Date.Year, o.Date.Month }); But now my grouping key is an anonymous type. I would…
Protector one
  • 6,926
  • 5
  • 62
  • 86
1
vote
1 answer

How to merge two Lists of IGrouping?

Given I have two lists of type IGrouping: List>: a) Key: 1 Values: "a", "b", "c" 2 "d", "e" b) 1 "aa", "bb", "cc" 3 "f", "g" And I would like to merge both to one: Key: 1 Values:…
Powerslave
  • 531
  • 2
  • 7
  • 24
1
vote
4 answers

IGrouping ElementAt vs. square bracket operator

IGrouping supports the ElementAt method to index into the grouping's collection. So why doesn't the square bracket operator work? I can do something like list.GroupBy(expr).Select(group => group.ElementAt(0)....) but not …
wrschneider
  • 17,913
  • 16
  • 96
  • 176
1
vote
0 answers

Binding ListView to IQueryable>

I'm binding a ListView to an IQueryable> generated using Linq-to-SQL like so: var lineChanges = dcOJ.LineAuthoriserChanges.GroupBy(g => g.tbl_line) .OrderBy(ord => ord.Key.tbl_journal.RefNo); lvLineAuthoriserChanges.DataSource =…
Dean Parker
  • 38
  • 1
  • 5
1
vote
1 answer

Generate IGrouping yourself

I have a list of instances of my own class "Vertrag" ("Contract") and need to group on them. A simple GroupBy does exactly what I need: Group by the last four fields, the result is an IEnumerable>. I can work with this result…
Ralf
  • 538
  • 1
  • 6
  • 17
1
vote
1 answer

Why can't I return an IEnumerable> as an IEnumerable>

I've used GroupBy(), and produced an IEnumerable>. And I can foreach over it, and pass each element (each IGrouping) into a method that accepts IEnumerable This is unsurprising - IGrouping
Brondahl
  • 7,402
  • 5
  • 45
  • 74
1
vote
1 answer

LINQ query with GroupBy causing "Unable to create a constant value of type 'System.Object'..."

I tried searching on this, but can't seem to find anything that matches my LINQ query to use to help me figure this one out. I'm getting a message in the debugger in the Results View->base object +base {"Unable to create a constant value of type…
CooperT
  • 63
  • 1
  • 11
1
vote
2 answers

How to Display IEnumerable> with an editor template

I have a bunch of items that I have grouped up by Header. I would like to display them on the page with the header text followed by the editor template for each individual item. I tried using nested templates as follows: Main Page: @Html.EditorFor(x…
Kelly
  • 3,292
  • 1
  • 24
  • 24