title: .NET Core Npgsql.EntityFrameworkCore ILikeExpression
body: <p>I am using EntityFramework Core with Npgsql provider, perform ILIKE query works fine:</p>
  
  <pre><code>var query = dbContext.countries
                        .Where(w =&gt; (w.name != null &amp;&amp; 
                                 EF.Functions.ILike(w.name, $"{search}%")
                         );
  </code></pre>
  
  <p>Query is translated into PostgreSQL's ILIKE, so far so good.</p>
  
  <p>I am also building a dynamic LINQ based on annotation - [Searchable] or [Orderable] properties in models - and I am trying to find out how to perform ILIKE using Expressions and Lambda. Code:</p>
  
  <pre><code> // works, except it produces just LIKE which is case sensitive. Not enough.
   expr = Expression.Call(property, nameof(string.Contains), new Type[] { }, Expression.Constant(search));
  
   // does not work, ends with exception, see below
   expr = new Npgsql.EntityFrameworkCore.PostgreSQL.Query.Expressions.Internal.ILikeExpression(property, Expression.Constant(search_query));
  </code></pre>
  
  <p>Any ideas? Thanks!</p>
  
  <pre><code>// Exception
  
  Application started. Press Ctrl+C to shut down.
  fail: Microsoft.AspNetCore.Server.Kestrel[13]
        Connection id "0HLGC19DMS3OI", Request id "0HLGC19DMS3OI:00000001": An unhandled exception was thrown by the application.
  System.ArgumentException: must be reducible node
     at System.Linq.Expressions.Expression.ReduceAndCheck()
     at System.Linq.Expressions.Expression.ReduceExtensions()
     at System.Linq.Expressions.Compiler.StackSpiller.RewriteExtensionExpression(Expression expr, Stack stack)
     at System.Linq.Expressions.Compiler.StackSpiller.RewriteExpression(Expression node, Stack stack)
     at System.Linq.Expressions.Compiler.StackSpiller.RewriteLogicalBinaryExpression(Expression expr, Stack stack)
     at System.Linq.Expressions.Compiler.StackSpiller.RewriteExpression(Expression node, Stack stack)
     at System.Linq.Expressions.Compiler.StackSpiller.RewriteLogicalBinaryExpression(Expression expr, Stack stack)
     at System.Linq.Expressions.Compiler.StackSpiller.RewriteExpression(Expression node, Stack stack)
     at System.Linq.Expressions.Compiler.StackSpiller.RewriteLogicalBinaryExpression(Expression expr, Stack stack)
     at System.Linq.Expressions.Compiler.StackSpiller.RewriteExpression(Expression node, Stack stack)
     at System.Linq.Expressions.Compiler.StackSpiller.RewriteLogicalBinaryExpression(Expression expr, Stack stack)
     at System.Linq.Expressions.Compiler.StackSpiller.RewriteExpression(Expression node, Stack stack)
     at System.Linq.Expressions.Compiler.StackSpiller.RewriteLogicalBinaryExpression(Expression expr, Stack stack)
     at System.Linq.Expressions.Compiler.StackSpiller.RewriteExpression(Expression node, Stack stack)
     at System.Linq.Expressions.Compiler.StackSpiller.RewriteExpressionFreeTemps(Expression expression, Stack stack)
     at System.Linq.Expressions.Compiler.StackSpiller.Rewrite[T](Expression`1 lambda)
     at System.Linq.Expressions.Expression`1.Accept(StackSpiller spiller)
     at System.Linq.Expressions.Compiler.StackSpiller.RewriteLambdaExpression(Expression expr)
     at System.Linq.Expressions.Compiler.StackSpiller.RewriteExpression(Expression node, Stack stack)
     at System.Linq.Expressions.Compiler.StackSpiller.ChildRewriter.Add(Expression expression)
     at System.Linq.Expressions.Compiler.StackSpiller.ChildRewriter.AddArguments(IArgumentProvider expressions)
     at System.Linq.Expressions.Compiler.StackSpiller.RewriteMethodCallExpression(Expression expr, Stack stack)
     at System.Linq.Expressions.Compiler.StackSpiller.RewriteExpression(Expression node, Stack stack)
     at System.Linq.Expressions.Compiler.StackSpiller.ChildRewriter.Add(Expression expression)
     at System.Linq.Expressions.Compiler.StackSpiller.ChildRewriter.AddArguments(IArgumentProvider expressions)
     at System.Linq.Expressions.Compiler.StackSpiller.RewriteMethodCallExpression(Expression expr, Stack stack)
     at System.Linq.Expressions.Compiler.StackSpiller.RewriteExpression(Expression node, Stack stack)
     at System.Linq.Expressions.Compiler.StackSpiller.RewriteExpressionFreeTemps(Expression expression, Stack stack)
     at System.Linq.Expressions.Compiler.StackSpiller.Rewrite[T](Expression`1 lambda)
     at System.Linq.Expressions.Expression`1.Accept(StackSpiller spiller)
     at System.Linq.Expressions.Compiler.StackSpiller.RewriteLambdaExpression(Expression expr)
     at System.Linq.Expressions.Compiler.StackSpiller.RewriteExpression(Expression node, Stack stack)
     at System.Linq.Expressions.Compiler.StackSpiller.ChildRewriter.Add(Expression expression)
     at System.Linq.Expressions.Compiler.StackSpiller.ChildRewriter.AddArguments(IArgumentProvider expressions)
     at System.Linq.Expressions.Compiler.StackSpiller.RewriteMethodCallExpression(Expression expr, Stack stack)
     at System.Linq.Expressions.Compiler.StackSpiller.RewriteExpression(Expression node, Stack stack)
     at System.Linq.Expressions.Compiler.StackSpiller.ChildRewriter.Add(Expression expression)
     at System.Linq.Expressions.Compiler.StackSpiller.ChildRewriter.AddArguments(IArgumentProvider expressions)
     at System.Linq.Expressions.Compiler.StackSpiller.RewriteMethodCallExpression(Expression expr, Stack stack)
     at System.Linq.Expressions.Compiler.StackSpiller.RewriteExpression(Expression node, Stack stack)
     at System.Linq.Expressions.Compiler.StackSpiller.RewriteExpressionFreeTemps(Expression expression, Stack stack)
     at System.Linq.Expressions.Compiler.StackSpiller.Rewrite[T](Expression`1 lambda)
     at System.Linq.Expressions.Expression`1.Accept(StackSpiller spiller)
     at System.Linq.Expressions.Compiler.LambdaCompiler.Compile(LambdaExpression lambda)
     at System.Linq.Expressions.Expression`1.Compile(Boolean preferInterpretation)
     at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.CreateExecutorLambda[TResults]()
     at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.CreateAsyncQueryExecutor[TResult](QueryModel queryModel)
     at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQueryCore[TFunc](Object cacheKey, Func`1 compiler)
     at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.ExecuteAsync[TResult](Expression query, CancellationToken cancellationToken)
     at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.ExecuteAsync[TResult](Expression expression, CancellationToken
  cancellationToken)
     at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ExecuteAsync[TSource,TResult](MethodInfo operatorMethodInfo, IQueryable`1 source, CancellationToken cancellationToken)
     at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.CountAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
  </code></pre>