当前位置:编程学习 > C#/ASP.NET >>

无法比较类型为“System.Linq.IGrouping`2”的元素。仅支持基元类型(例如 Int32、String 和 Guid)和实体类型。

var q = from a in db.Budget_details
                        join b in db.Budget on a.Items equals b.Items into ab
                        from s in ab.DefaultIfEmpty()

                        where area.Contains(a.area)
               && month.Contains(a.month) && items.Contains(a.Items)
              && type.Contains(a.type) && lb.Contains(a.depart)

                        group new {a.Price,s.yusuan } by new { a.type, a.Items } into g

                        orderby g.Key
                        select new
                        {
                            type = g.Key.type,
                            items = g.Key.Items,
                            yusuan = g == null ? 0 : g.Sum(c => c.yusuan),
                            reality = g == null ? 0 : g.Sum(c => c.Price),
                            rest = g == null ? 0 : g.Sum(c => c.yusuan) - g.Sum(c => c.Price)
                        };
              
                var result = q.Skip((page - 1) * rows).Take(rows).ToList();
                Dictionary<string, object> json = new Dictionary<string, object>();
                json.Add("total", q.ToList().Count);
                json.Add("rows", result);


                return Json(json, JsonRequestBehavior.AllowGet);
我原本是想左连接没有值的则显示为空或0,
利用三元表达式后报错如无法比较类型为“System.Linq.IGrouping`2”的元素。仅支持基元类型(例如 Int32、String 和 Guid)和实体类型,如果不用group by 则没有问题,请高手指点啊。
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,