升级到 EF Core 3 破坏了所有 LINQ 查询

Upgrading to EF Core 3 Broke All LINQ Queries

我在收到错误后阅读了原因 (https://docs.microsoft.com/en-us/ef/core/querying/client-eval) 并理解了解释,但我不确定需要更改哪些内容。

所以这行不通:

var result = (from ts in _context.TradesSeries
                          join tts in _context.TradesTrades
                          on ts.Id equals tts.SeriesId
                          where seriesIds.Contains(tts.SeriesId) && tts.FirstPartyId == null &&
                                tts.Status != "closed" && tts.Status != "cancelled"
                          group new { ts, tts } by new { tts.SeriesId } into g
                          select new TotalByIsin
                          {
                              SeriesId = g.Key.SeriesId,
                              IsinShortCode = g.Select(i => i.ts.Number).Distinct().First(),
                              Isin = g.Select(i => i.ts.Isin).Distinct().First(),
                              Amount = (double)g.Sum(pt => pt.tts.Amount),
                              NumberOfTrades = g.Count()
                          }).ToList();
            return result;

这也不会:

var result = (from tt in _context.TradesTrades
                          join ts in _context.TradesSeries on tt.SeriesId equals ts.Id
                          join ttd in _context.TradesTradeDistributors on tt.Id equals ttd.TradeId
                          join to in _context.TradesOrganisations on ttd.DistributorId equals to.Id
                          where seriesIds.Contains(tt.SeriesId) && tt.FirstPartyId == null &&
                                      tt.Status != "closed" && tt.Status != "cancelled" && 
                                      to.DefaultDistributor !=1 && to.ExcludeDistSponView !=1 && to.ExcludeFromDwdpTotal !=1
                          join tc in _context.TradesCountries on to.CountryId equals tc.Id into tcj
                          from tc in tcj.DefaultIfEmpty() // GroupJoin -> left join
                          group new { tt, ts, ttd, to, tc } by new { ttd.DistributorId}
                          into tradeg
                          let commissionTotal = tradeg.Sum(trade => trade.ttd.Commission)
                          orderby commissionTotal descending
                          select new TopDistributors
                          {
                              //SeriesId = tradeg.Key.SeriesId,
                              DistributorName = tradeg.First().to.Name,
                              IsinShortCode = tradeg.First().ts.Number,
                              CountryName = tradeg.First().tc == null ? "N/A" : tradeg.First().tc.Name,
                              Amount = Math.Ceiling((double) commissionTotal)
                          }).Take(5).ToList();
             return result;

...我在 Whosebug LINQ 专家的帮助下构建的其他 30 个奇怪查询中的任何一个都不会。在这些查询中什么被认为是客户,什么不是?有没有简单的修复方法来解决这个问题,或者我应该只使用 Dapper 并直接 SQL 以防万一 Microsoft 决定再次破坏 LINQ 功能?虽然,我宁愿不必在团队其他成员明天早上进入之前完全重写 30 个查询。 ‍♂️

谢谢!

我能够回滚 Pomelo.EntityFrameworkCore.MySql 到版本 2.2.6,并且一切正常。

将调查什么是客户端,什么不是客户端,因为 Ian 提供了一个 link 和一个包含函数调用的示例 - 这实际上没有回答我发布的问题。我仍然不知道什么是客户端,什么不是……例如,LET 是客户端的东西吗?

这是因为重大更改阻止了自动客户端评估。

您可以在联接中使用 AsEnumerable(),然后使用无法转换为 SQL 的 groupBy 和 select。