score:1
Accepted answer
It's not clear why you're using First()
to start with. How about:
var grouped = linqQuery.GroupBy(f => f.OwnerId).ToList();
Now each entry in "grouped" is a grouping. You can now use:
foreach (var group in grouped)
{
Console.WriteLine("OwnerId: {0}", group.Key);
int leadCount = group.Count(c => c.LeadStatus == 100000000);
// etc - do what whatever else you want with the group
// Let's dump all the customer IDs...
foreach (var entry in group)
{
Console.WriteLine(entry.CustomerID);
}
}
score:2
It sounds like you want to use all the items in myGroup
. By calling First()
you're limiting yourself to the first item only.
You could write your query as follows:
var query = from f in linqQuery.ToList()
group f by f.OwnerId into myGroup
from item in myGroup
select new
{
OwnerName = item.OwnerName,
OwnerId = item.OwnerId,
LeadStatus = item.LeadStatus.ToString(),
EmailedToRSM = item.EmailedToRSM,
OrderCount = myGroup.Count()
};
However, note that by doing so you would be flattening the results.
Source: stackoverflow.com
Related Articles
- LINQ Checking all Records in Group
- LINQ Source Code Available
- LINQ In Clause With Group By And TOP N Records Within Each Group
- C# LINQ get records from datatable group by hour
- creating Linq to sqlite dbml from DbLinq source code
- how to use group by in linq C# and fetch the list of records
- LINQ query to group records by month within a period
- How to write an linq statement to get the last of a group of records
- How to use LINQ Group Records and use Distinct
- linq Group By and take first and lats records
- get ID of latest records in a group by linq query
- How to Select top (5) contributors group by Business type code in c# linq query
- How to create linq to get all records group by columnname
- source code for LINQ 101 samples
- How to count group of records using LINQ Query?
- How do you use linq to group records based on an accumulator?
- Group records stored in one-dimensional array using LINQ
- Converting SQL to LINQ needing to group records created per second
- Linq group with sum function and nested records
- Group by using Linq to get unique records from list
- Linq newest group of records
- Building linq query that collect records by group
- Most efficient way to group records alphabetically with LINQ
- using a group by in linq to select aggregated records
- LINQ to SQL Group By Multiple Records in One Row
- c# Linq or code to extract groups from a single list of source data
- group child records by parentid and sum the amount linq C#
- How to get group of records with latest date using Linq to Entities
- LinQ to get the latest group of records satisfying a condition
- linq query to sort and then bring a particular group of records to top
- Linq query - Join 2 tables
- Linq join values from two lists
- Linq distinct record containing keywords
- Want Autonumbering as financial year then five digit number (razor, C#, linq) ex. 201400001 then 201400002
- LINQ GroupBy over
- Is List.ForEach technically a part of LINQ or not?
- New to Linq; need to grab multiple values from single row
- Need to know if this lambda can be converted to LINQ syntax and how
- Select values with max date for each ID
- Get rating for products and product category
- Duplicates while querying Three tables to get Common values using LINQ.
- How to set conditional filter in where clause using linq?
- Ordering a Grouped Result in C#
- When I'm adding rows, I only get 1 object in database
- How does Linq projection work between Extention Method and query expression
- in mongodb, what is the most efficient way to get the first and last document
- How to fill an Windows Forms combobox using DbfDotNet?
- How to get Swedish sort order for strings
- Generic implementation of querying - LINQ expression could not be translated
- How to write a LINQ query with inner join conditions and IN sub query