✅ EF.Functions.Like() produces an exception
I'm working with
EF Core
with PostgreSQL
, I have the following Asp.Net Core's Action
:
After trying to test that action I get this exception: System.InvalidOperationException: The LINQ expression 'nick => __Functions_0 .Like( matchExpression: nick, pattern: "%ti")' 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 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'.Please do you have any idea about how to fix this issue without using
AsEnumerable()
?
Massive thanks in advance <38 Replies
Unknown User•16mo ago
Message Not Public
Sign In & Join Server To View
Didn't get anything from docs (https://learn.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.dbfunctionsextensions.like?view=efcore-7.0)
DbFunctionsExtensions.Like Method (Microsoft.EntityFrameworkCore)
An implementation of the SQL LIKE operation. On relational databases this is usually directly translated to SQL.
Unknown User•16mo ago
Message Not Public
Sign In & Join Server To View
I fixed it using
StartsWith()
extension method for string
Unknown User•16mo ago
Message Not Public
Sign In & Join Server To View
Yeah, I think the issue was because of the nested using of the
EF.Functions.Like()
inside the Any()
function, but it works fine when it used inside a Where
without nested function inside the same Where
Unknown User•16mo ago
Message Not Public
Sign In & Join Server To View
Yeah that was right
Also the
NickNames
property is an Array
in the PostgreSQL
and not an entity maybe this is another cause of this issue