简体   繁体   English

LINQ 包含基于 Entity Framework Core 3.1 中的多个搜索条件的条件

[英]LINQ Contains condition based on multiple search criteria in Entity Framework Core 3.1

I have a string parameter that's split up into multiple search filters depending on the outcome of a Split(',') operation.我有一个字符串参数,它根据Split(',')操作的结果分成多个搜索过滤器。 I want to select all entities where the title field contains any of the search filters我想 select 标题字段包含任何搜索过滤器的所有实体

I'd expect the following LINQ to work我希望以下 LINQ 能够工作

    string[] filters = param.Split(',');

    var query = await
        (from t in this.Context.Persons
         from f in filters.Where(f => t.Title.Contains(f))
         select t).ToListAsync();

However exequting the query I'm getting the following error:但是执行查询时出现以下错误:

Processing of the LINQ expression 't => __filters_0
    .Where(f => t.Title.Contains(f))' by 'NavigationExpandingExpressionVisitor' failed. This may indicate either a bug or a limitation in EF Core. 

Any assistance is appreciated.任何帮助表示赞赏。

I ended up implementing a generic LikeAny extension method on IQueryable as described here: https://github.com/dotnet/efcore/issues/10834我最终在 IQueryable 上实现了一个通用的 LikeAny 扩展方法,如下所述: https://github.com/dotnet/efcore/issues/10834

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM