一切福田,不離方寸,從心而覓,感無不通。

贴一下聚合函数在LinQ to Object和LinQ to DataSet中的用法

     var member = new Member();

            int recordCount;
            var memberInfos = member.Paging(20, 1, "MemberId DESC", "", out recordCount);
            var memberIdSum = memberInfos.Sum(c => c.MemberId);
            Response.Write(memberIdSum.ToString());
            Response.Write("<br/>——————————————————-<br />");
 
            var dbHelper = DbFactory.AccessSqlServer;
            var dbPaging = DBPaging.Create(dbHelper);
            var ds = dbPaging.GetListByPage(20, 1, "Member", "", "MemberId DESC");
            var memberIdSum2 = from order in ds.Tables[0].AsEnumerable()
                               group order by order.Table into g
                               select new
                               {
                                   TotalDue = g.Sum(c => c.Field<Int32>("MemberId")),
                               };
            foreach (var row in memberIdSum2)
            {
                Response.Write(row.TotalDue+"<br />");
            }