我需要在select语句中获取索引。
我的代码:
IQueryable grpdRows;
dtInput = ds.Tables[0];
grpdRows = dtInput
.Select("", "partno")
.AsQueryable()
.GroupBy("new (iif(it[\"partno\"] == null, \"\", it[\"partno\"]) as GrpKey1)","it")
.Select("new (it.Key.GrpKey1 as GrpKey1, it.Count() as TotalCount")");
如何在select语句示例中获取索引:
.Select("new (it.Key.GrpKey1 as GrpKey1, it.Count() as TotalCount, **it.Index**")");
答案 0 :(得分:0)
我不确定通过Dynamic Linq可以实现这一点,但是作为解决方法,你可以尝试这样的事情:
IQueryable grpdRows;
dtInput = ds.Tables[0];
grpdRows = dtInput
.Select("", "partno")
.AsQueryable()
.GroupBy("new (iif(it[\"partno\"] == null, \"\", it[\"partno\"]) as GrpKey1)","it")
.Select("new (it.Key.GrpKey1 as GrpKey1, it.Count() as TotalCount)");
var res = (from dynamic row in grpdRows
select row).Select((row,index)=>new {row.GrpKey1, row.TotalCount, Index=i});