从 EF Core 2 迁移到 EF Core 3 ...无法翻译

Migrating from EF Core 2 to EF Core 3 ... could not be translated

将我的项目从 ef core 2.2 升级到 ef core 3.1 后,我的几乎所有 entity framework LINQ 查询都损坏了

这是一个我遇到问题的例子:

System.AggregateException: 'One or more errors occurred. (The LINQ expression 'DbSet .Where(b => b.IsDeleted == __displayIsDeleted_0) .Where(b => __properties_1 .Any(p => p.GetValue((object)b) != null && p.GetValue((object)b).ToString().IndexOf( value: __8__locals1_query_2, comparisonType: InvariantCultureIgnoreCase) >= 0))' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to either AsEnumerable(), AsAsyncEnumerable(), ToList(), or ToListAsync(). See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.)'

public static IQueryable<T> WhereDynamic<T>(
        this IQueryable<T> sourceList, string query)
    {

        if (string.IsNullOrEmpty(query))
        {
            return sourceList;
        }
        try
        {

            var properties = typeof(T).GetProperties()
                .Where(x => x.CanRead && x.CanWrite && !x.GetGetMethod().IsVirtual);

            //Expression
            sourceList = sourceList.Where(c =>
                properties.Any(p => p.GetValue(c) != null && p.GetValue(c).ToString()
                   /* .Contains(query, StringComparison.InvariantCultureIgnoreCase)*/
                   .IndexOf(query, StringComparison.InvariantCultureIgnoreCase) >= 0 ));
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
        }

        return sourceList;
    }

如果可能,请告诉我应该对此代码进行哪些更改

当无法将 C# 转换为 SQL 时,EF Core 2 在客户端执行代码。默认情况下在 EF Core 3 中禁用此选项,您可以使用以下代码实现相同的行为

sourceList = sourceList
     .ToList()
     .Where(c =>
         properties.Any(p => p.GetValue(c) != null && p.GetValue(c).ToString()
              .IndexOf(query, StringComparison.InvariantCultureIgnoreCase) >= 0 ))
     .AsQueryable();

在此article

中详细了解客户评价