EKsumic's Blog

let today = new Beginning();

Click the left button to use the catalog.

OR

C#Winform使用 .NET FrameworkCore出现Client side GroupBy is not supported 怎么办?

System.InvalidOperationException:“Client side GroupBy is not supported.”

客户端不支持GroupBy语句。

事故现场:

var q1 = Team1.GroupBy(x => x.T1 + x.T2 + x.T3 + x.T4 + x.T5, x => x.T1 +","+ x.T2 +","+ x.T3  +","+  x.T4 +","+ x.T5).OrderByDescending(x=>x.Count());
var q2 = Team1.GroupBy(x => x.T1 + x.T2 + x.T3 + x.T4 + x.T5, x => x.T1 +","+ x.T2 +","+ x.T3  +","+  x.T4 +","+ x.T5).OrderByDescending(x => x.Count());
var q3 = Team1.GroupBy(x => x.T1 + x.T2 + x.T3 + x.T4 + x.T5, x => x.T1 +","+ x.T2 +","+ x.T3  +","+  x.T4 +","+ x.T5).OrderByDescending(x => x.Count());

var maxTeam1 = q1.FirstOrDefault();
var maxTeam2 = q2.FirstOrDefault();
var maxTeam3 = q3.FirstOrDefault();

具体报错:

Error

解决方案:

先在内存里面开辟一个空间用来存储List。

即在GroupBy之前,添加ToList()方法。

参考答案来源于方案3,但这似乎看起来并不是长久之计。

 

参考方案:

https://stackoverflow.com/questions/58138556/client-side-groupby-is-not-supported

https://stackoverflow.com/questions/61357820/using-groupby-in-linq-client-side-groupby-is-not-supported

https://entityframeworkcore.com/knowledge-base/60432078/asp-net-core-web-api--client-side-groupby-is-not-supported

This article was last edited at 2020-09-10 23:47:43

* *