总结Linq C#中的字段

时间:2016-09-24 22:39:21

标签: c# linq

在下面的linq声明中,我需要总计totalhours,directhours&按名称分组的间接小时数

这可能是一个菜鸟问题,因为我是Linq的新手。

var Empl = from Evw in EViews.AsEnumerable()
            where Evw.Field<string>("Type") == "Egh" &&
                  Evw.Field<string>("Org") == orgname
                  select new
                  {
                    RowLabel = (string)Evw["Name"],
                    TotalHours = (decimal)Evw["TotalHours"],
                    DirectHours = (decimal)Evw["DirectHours"],
                    IndirectHours = (decimal)Evw["IndirectHours"],
                   };

提前致谢!

1 个答案:

答案 0 :(得分:0)

请检查Article

你可以获得这个LINQ的组值

 var Empl = from Evw in EViews.AsEnumerable()
                where Evw.Field<string>("Type") == "Egh" &&
                      Evw.Field<string>("Org") == orgname
                      group Evw by Evw.Name into g
                      select new
                      {
                        RowLabel = g.Key,
                        TotalHours = g.Sum(x=>x.TotalHours)
                       };