List 与 table 分组(group by )

 

1.list 分组

List<ADSPkgMasterInfo> packageList= BizUIRequestAssetTag.GetUIRequestAsset_Rel_PackageNameInfo(_UIRequestID, _isDraft);
        var aa = from item in packageList
                 group item by new { item.PkgName, item.PkgMasterID } into g
                 select new
                 {
                     PkgName = g.Key.PkgName,
                     PkgMasterID = g.Key.PkgMasterID
                 };

 

2.table 分组

 

var Query = from t in dtACCQueryInfo.AsEnumerable()
                        group t by new
                        {
                            s = t.Field<string>("SenseVersion"),
                            d = t.Field<string>("Device"),
                            a = t.Field<string>("APName"),
                            fn = t.Field<string>("OwnerName"),
                            Fd = t.Field<string>("CodeFreezeDate")
                        }
                            into m
                            select new
                            {
                                SenseVersion = m.Key.s,
                                Device = m.Key.d,
                                APName = m.Key.a,
                                OwnerName = m.Key.fn,
                                CodeFreezeDate = m.Key.Fd,
                                count = m.Count()
                            };

posted on 2015-09-07 15:16  乖乖的小莹儿  阅读(482)  评论(0编辑  收藏  举报