Questions tagged [linq-group]
139 questions
2
votes
1 answer
Return List after group by
I have a function
public List UserList()
{
var q = from i in _dataContext.PageStat group i by new { i.UserName } into ii select new { ii.Key.UserName };
}
How can I return List?

kusanagi
- 14,296
- 20
- 86
- 111
2
votes
4 answers
LINQ - Group List to Year, Month, Day
I have a simple list
T.Date = 11/04/2014, T.Title = "Book1", T.Tipology = "Book"
T.Date = 14/04/2014, T.Title = "Book2", T.Tipology = "Book"
T.Date = 02/05/2015, T.Title = "Spot1", T.Tipology = "Spot"
T.Date = 21/06/2015, T.Title = "Newspaper1",…

Sauron
- 2,156
- 5
- 17
- 20
2
votes
1 answer
Lambda Query GroupBy with boolean values
I have a number of instances where I need to return a data list that uses .GroupBy. In addition to dates and integers I also need to return Boolean values, which I cannot seem to do. An example model:
public class HolidayCheckList
{
public…

PawnSacrifice
- 57
- 1
- 7
2
votes
1 answer
How to select multiple counts grouped by date in EF
I have a table that looks roughly like this:
Date | Category | Name
01/02/2014 | A | Foo
01/02/2014 | B | Bar
02/02/2014 | A | Baz
02/02/2014 | A | Bla
I am trying to build a query that produces something…

hndr
- 757
- 13
- 29
2
votes
3 answers
LINQ to SQL join when there aren't results
Given the following database structure
alt text http://dl.dropbox.com/u/26791/tables.png
I'm trying to write a LINQ query that will return images grouped by tags it's associated with. So far I've got this:
var images = from img in db.Images
…

Boarder2
- 162
- 9
2
votes
1 answer
Linq select same id and remove other
I need to filter this list.
I just want to have those person that have the same SalId and those must be at least two.
How do I do it?

Don Juan
- 171
- 2
- 17
2
votes
1 answer
Linq Lambda expression for below sql in vb.net
I have this existing Sql statement:
Select Count(ordid),isnull(prcsts,'NOT STARTED')
from lwp
where lwp in( Select max(Id) from lwp group by ordid)
group by prcsts
I want to convert to use linq-to-sql, but I'm can't figure out how to handle the…

tinku99
- 25
- 5
2
votes
2 answers
How to group in Linq based on previous Value
I want to group a pointcloud based on 2 conditions
simple on Y so I wrote pointcloudH.GroupBy(KVP => KVP.Value.Y) where KVP is an KeyValuePair
and now I want to group it also by X if X == (previousX + 1)
as far as I…

WiiMaxx
- 5,322
- 8
- 51
- 89
2
votes
1 answer
LINQ Group and Count with a Max
Can someone write a LINQ query for the following please
Given the data below I need the following
The Player with the highest score each week and the count of them if they win more than one week. If a tie results for the top score in a week then…

Mark Lawson
- 289
- 1
- 4
- 12
2
votes
2 answers
Dynamic Grouping Using LINQ
Please have a look at below example. The Group Clause has to be dynamic. Can you please guide me how this can be achieved. i.e. the row
{ r.Portfolio, r.DataType }
has to be constructed dynamically.
Not sure how I can tweak the solution as given…

user2051980
- 39
- 1
- 5
1
vote
2 answers
Access LINQ to SQL results with a group clause
I have a LINQ to SQL query and I'm having trouble to access the results.
Without the 'group' clause, it works fine, but with the group clause the resulting fields seems to be missing.
var q = (from p1 in db.Personnel
join t2 in db.Table2 on…

Cameron Castillo
- 2,712
- 10
- 47
- 77
1
vote
4 answers
Count same string count out of massive string list
I have got over 600k lines of string. I want to group same strings and learn their counts.
So example
i go to school
i like music
i like games
i like music
i like music
i like games
i like music
So result will be
i go to school , 1
i like games ,…

Furkan Gözükara
- 22,964
- 77
- 205
- 342
1
vote
1 answer
Get Linq Group into a User Defined Type
I am working on a c# project and writing a LINQ query, in this query I need to create a group, but I know I want to use that group type, but the type of the group gives me some trouble as I am not able to cast it to my desired type.
My Query is…

manav inder
- 3,531
- 16
- 45
- 62
1
vote
1 answer
Tricky Linq Group by for time ranges
I have a class that represents a shift that employee's can work:
public class Shift {
public int Id { get; set;}
public DateTime Start {get;set;}
public DateTime End { get; set;}
public DayOfWeek Day { get; set;}
}
And say I have a…

Alan
- 45,915
- 17
- 113
- 134
1
vote
1 answer
Grouping and summing by Linq
I would like to get the total order amount for each customer with Linq, I know I need to group and sum I have only succeeded to group without summing the whole amount for each order.
var OrderByCustumer = new[] {
new { name = "cust1", order…

Jaafar Jaafar
- 13
- 3