tags:

views:

486

answers:

2

I want to create this query:

select Something, count(Something) as "Num_Of_Times"
from tbl_results
group by Something
having count(Something)>5

I started with this:

tempResults.GroupBy(dataRow => dataRow.Field<string>("Something"))
   .Count() //(.......what comes here , to make Count()>5?)
+1  A: 
from item in tbl_results
group item by item.Something into groupedItems
let count = groupedItems.Count()
where count > 5
select new { Something = groupedItems.Key, Num_Of_Times = count };


UPDATE : This would give you the result as an IQueryable<DataRow> :

DataTable dt= new DataTable();
dt.Columns.Add("Something", typeof(int));
dt.Columns.Add("Num_Of_Times", typeof(int));

var results =   (from item in tbl_results
                 group item by item.Something into groupedItems
                 let count = groupedItems.Count()
                 where count > 2
                 select dt.Rows.Add(groupedItems.Key, count)).AsQueryable();

(note that it also fills the dt table)

Thomas Levesque
Thank you very much, i need the result as IQueryable<DataRow>, Is there a way to create the 'select' result as a IQueryable<DataRow>? or do i need to create the rows manually?
Rodniko
see updated answer
Thomas Levesque
Thank you very much :)
Rodniko
A: 

Thanks! it helped me a lot.

EMorato