[英]Query datatable using linq to get count order by
我有一個DataTable,如下所示。 我需要使用linq查詢它
像這樣的查詢在linq
select B, Count(C)
from DataTable
group by B
嘗試這個:
db.DataTable
.GroupBy(x => x.B)
.Select(new { B = x.Key, CountC = x.Count(y => y.C) });
嘗試這個:
var qry = datatable1.AsEnumerable()
.GroupBy(a=>a.Field<type>("FieldB"))
.Select(grp=>new
{
value = grp.Key,
count = grp.Count(c=>c.Field<type>("FieldC"))
});
用適當的數據類型替換type
,例如: int
, string
等。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.