EF Core 3.1 throws when running the following query, complaining that it could not generate the right SQL for it.
var searchPatterns = new string[] { "a", "b", "c" };
var matches = from entity in _dbContext.Entity
where searchPatterns.Any(x => entity.Column1.Contains(x))
select entity;
In raw sql, this could translate to something like
select * from entity
where exists (select x from @SearchPatterns where entity.column1 like '%:' + x + '%'))
(where @SearchPatterns
is a table parameter that holds the records a
, b
, and c
)
How can I rewrite the query to make it possible for EF Core to accept it?
Edit The actual query that I am building is much more complicated than the simplified version I presented above. Thus, I am not considering FromSqlRaw()
as an option that I am willing to use.
question from:
https://stackoverflow.com/questions/65840571/ef-core-complex-where-clause 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…