Comments are closed for this post.
Posted by
Kamesh Bora
@
17 Jun 2009
10:31 PM
How do we convert the var Groups to an IList<something>?
Posted by
josh
@
18 Jun 2009
12:16 AM
groups.ToList()?
Not sure what you mean. If you mena not using anonymous types then you'll need a type with the appropriate properties, e.g.
public class MyType
{
public string Dept { get; set;}
public DateTime EarliestEmployeeStartDate { get; set;}
}
And then the query would be:
from emp in employees
group emp by emp.Dept into g
select new MyType { Dept = g.Key, StartDate = g.Min(e => e.DateTime) };
This would return IEnumerable<MyType> and there's an extension method .ToList() if you really want List<MyType>
Posted by
Gustaf Lindqvist
@
12 Mar 2010
3:56 AM
Thanks a lot, you just saved me a lot of time. I Read your post and could really easily translate it into my problem, even though it became a little bit more complex. The conclusion is that you explained it pedagogically!
Thanks a lot!
Posted by
San
@
08 Jun 2010
12:08 PM
Thanks Josh. For a LINQ beginner like me this is what i exactly needed, The explanation & conversion to a list<Mytype> was very useful.I needed LINQ results in typed Classes rather than in anoynomous.
Posted by
Peternac
@
09 Jan 2011
2:03 PM
I try to build a LINQ statement where the list of fields is
empty but I cannot get it done.
This works:
Dim q = From p In dt_TAttrDataForData_Id _
Group By p.Attribute_Id Into inputFormula = GroupResults(p.Attribute_Id + "#" + p.Value)
Select New With {inputFormula}
but what I want is this:
Dim q = From p In dt_TAttrDataForData_Id _
Group By Into inputFormula = GroupResults(p.Attribute_Id + "#" + p.Value)
Select New With {inputFormula}
Can you give me same help?
Posted by
Arvi
@
23 Feb 2011
2:25 AM
How can we then enumerate the grouped items later on? For instance, I wish to later project the names of the employees in a certain department, i'd ideally like to do something like
var groups = from emp in employees
group emp by emp.Dept into g
select new { Dept = g.Key, Names = g.SelectMany(x=>Name).ToList() }; or something of that nature. However, this doesn't work. What would be a good alternate query to accomplish this? Thanks.