首页 > 代码库 > 一个Linq

一个Linq

public class CalendaerCollectItem{    public int ID { get; set; }    public string Name { get; set; }    public int Finished { get; set; }    public int NotFinished { get; set; }}
////按照员工ManagerUserID筛选出最终要显示的结果            var query = from t in dtSource.AsEnumerable()                        group t by new { t1 = t.Field<Int16>("ManagerUserId"), t2 = t.Field<string>("Name") }                            into m                            select new                            {                                ID = m.Key.t1,//ManagerUserID                                Name = m.Key.t2,//客服的名字                                Finished = m.Count(n => n.Field<Int16>("status").Equals(2)), //统计完成的                                NotFinished = m.Count(n => n.Field<Int16>("status").Equals(1)) //统计未完成的                            };            //存到List中提交到前台            List<CalendaerCollectItem> list = new List<CalendaerCollectItem>();            query.ToList().ForEach(a =>            {                CalendaerCollectItem item = new CalendaerCollectItem();                item.ID = a.ID;                item.Name = a.Name;                item.Finished = a.Finished;                item.NotFinished = a.NotFinished;                list.Add(item);            });

 

一个Linq