I have a DataTable something like shown below. i need to query it using linq
Something like this Query in linq
select B, Count(C)
from DataTable
group by B
Try this:
db.DataTable
.GroupBy(x => x.B)
.Select(new { B = x.Key, CountC = x.Count(y => y.C) });
Try this:
var qry = datatable1.AsEnumerable()
.GroupBy(a=>a.Field<type>("FieldB"))
.Select(grp=>new
{
value = grp.Key,
count = grp.Count(c=>c.Field<type>("FieldC"))
});
Replace type
with proper data type, such as: int
, string
, etc.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.