am able to create an invoke Expression with SQL Functions like as shown below
var likeMethod = typeof(DbFunctionsExtensions).GetMethod("Like", new[] { typeof(DbFunctions), typeof(string), typeof(string) });
Expression.Call(null, likeMethod, Expression.Constant(EF.Functions), searchKeyExpression, Expression.Constant($"%{filter.Value}%"));
I just need to understand how can I use the functionality for columns like integer or decimal column to use with Like functions. If I use the above expression I am getting below error. How can I use expression with ef like with non string datatype
Argument Exeption: argument exception in Expression of System.Int32 can not be used for parameter for type System.String of method Boolean Like (Ef.DBfuntions)
Steps to reproduce
var likeMethod = typeof(DbFunctionsExtensions).GetMethod("Like", new[] { typeof(DbFunctions), typeof(string), typeof(string) });
Expression.Call(null, likeMethod, Expression.Constant(EF.Functions), searchKeyExpression, Expression.Constant($"%{filter.Value}%"));
As I can see there is an option for to do it in Ef.Functions Like method in the below example
context.Set<MyEntity>().Where(e => EF.Functions.Like((string)(object)e.IntCol, "%1%"))
but how can I do this using Member Expressions.
Source :- https://github.com/aspnet/EntityFrameworkCore/issues/9578
This is the solution for direct line query. https://github.com/aspnet/EntityFrameworkCore/issues/16195
Further technical details
EF Core version: (ASP.NET Core 2.1) Database Provider: (e.g. Microsoft.EntityFrameworkCore.SqlServer) Operating system: IDE: (e.g. Visual Studio 2017 15.4)