fc123
fc123

Reputation: 918

linq group by statement not working

I have a linq statement like following,

var v1 = from s in context.INFOONEs group s by s.DATET into xyz select xyz;

I am trying like following to display the results

foreach (var x in v1)
{
    Console.WriteLine(x.);
}

But intellisence is not showing the columns when I type x.

What I am doing wrong? And what is the right way to achieve what I am trying to accomplish?

Thanks

Upvotes: 0

Views: 122

Answers (1)

Selman Genç
Selman Genç

Reputation: 101681

because there is no column in x. There are some record(s) under each group.So you need to get those records:

foreach (var x in v1)
{
    Console.WriteLine(x.Key); // display the Key of current group
    foreach(var item in x) // iterate over the records in the group
    {
       Console.WriteLine(item.) // here you can access your columns
    }
}

Upvotes: 9

Related Questions