如何清除错误“无法比较类型'System.Linq.IGrouping`2的元素”

时间:2014-02-10 09:49:16

标签: c# linq entity-framework

使用 vs2012 C#ef 。我的语法linq语法显示错误,如果我添加 AsEnumerable()那么它的工作正常但它会使查询变慢,慢意味着很慢。该怎么做。如何避免此错误

var query = (
                    from bm in this.Context.BilBillMasters

                        join g in
                            (
                                from c in this.Context.BilBillDetails
                                group c by new { c.BillID }
                            )
                        on bm.BillID equals (g == null ? 0 : g.Key.BillID) into bDG
                        from billDetailGroup in bDG.DefaultIfEmpty()


                        where bm.IsDeleted == false
                        && (companyID == 0 || bm.CompanyID == companyID)
                        && (userID == 0 || bm.CustomerID == userID)
                        select new
                        {
                            bm.BillID,
                            BillNo = bm.CustomCode,
                            bm.BillDate,
                            BillMonth = bm.MonthFrom,
                            TransactionTypeID = bm.TransactionTypeID ?? 0,
                            CustomerID = bm.CustomerID,
                            Total = billDetailGroup.Sum(p => p.Amount),


                            bm.ReferenceID,
                            bm.ReferenceTypeID

                        }
                        );

                return query.OrderByDescending(e => e.BillID);

错误消息 enter image description here

如果有任何查询请问。谢谢。高级。任何类型的建议都是可以接受的。

1 个答案:

答案 0 :(得分:1)

您创建没有比较器的匿名类:

group c by new { c.BillID }

而是尝试

group c by c.BillID