System.NotSupportedException: LINQ to Entities 不识别方法“System.Decimal ToDecimal(Int32)”,因此该方法无法转换为存储表达

来源:互联网 发布:淘宝的流量是什么意思 编辑:程序博客网 时间:2024/05/05 22:49
 var sectionBasin = (from s in section
                                    join b in standard
                            on s.SectionCode equals b.SectionCode
                                    select new
                                    {
                                        SectionCode = s.SectionCode,
                                        Province = s.Province,
                                        Standard = b.Standard

                                    }) .GroupBy(x => x.Province).Select(t => new
                                    {
                                        code = t.Key,
                                        upStd = t.Where(x => x.Standard == 0).Count(),
                                        subStd = t.Where(x => x.Standard == 1).Count(),
                                        upsub=t.Count(),
                                        rate = Convert.ToDecimal(t.Where(x => x.Standard == 0).Count()) / Convert.ToDecimal(t.Count())

                                    });


报错:

System.NotSupportedException: LINQ to Entities 不识别方法“System.Decimal ToDecimal(Int32)”,因此该方法无法转换为存储表达


改成先List,再GroupBy

 }).ToList() .GroupBy(x => x.Province).Select(t => new

0 0