Reputation: 568
I'm beginner in linq to sql
this:
var query = (from p in behzad.STATUS
select p);
var taskCounts = (from worker in query.ToList()
group worker by worker.date into g
select g.Select(x=>x.natije)
).ToArray();
but in in this line select g.Select(x=>x.natije)
select just x.natije
,i want select another filed x.qaza
,how can i write that?
Upvotes: 0
Views: 760
Reputation: 21795
Simply create an anonymous type:-
var taskCounts = (from worker in query
group worker by worker.date into g
select g.Select(x=> new { natije = x.natije, qaza = x.qaza } );
Since this returns IEnumerable<IGrouping<T,T>>
you will have to use two foreach
loops to get the data:-
foreach (var item in taskCounts)
{
foreach (var x in item)
{
tempo = x.natije //here
}
}
Also, you can find the first natije
from first group but it may result in error:-
string tempo = res.First().First().natije;
Upvotes: 1
Reputation: 3705
You can creat a dynamic object on the select:
var query = (from p in behzad.STATUS
select p);
var taskCounts = (from worker in query.ToList()
group worker by worker.date into g
select g.Select(x=> new { Natije = x.natije, Qaza = x.qaza })
).ToArray();
Upvotes: 0