System.Linq.Dynamic.Core: Cannot use with EF.Functions.ILike(anything, "%aaa%")

I get error:

No property or field 'EF' exists in type 'xxxxx'

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 15 (4 by maintainers)

Most upvoted comments

Hello @mhosman ,

Here is an online example with WhereDynamic using a simple where clause and one using EF.Functions.Like

Example: https://dotnetfiddle.net/xCaJr8

In your case, you missing the x in x.status,

It should have been .WhereDynamic(x => "x.status == true").

It looks like we could improve this part to allow property without having to specify the x but for now, you must use a valid C# syntax.

@mhosman ,

Everything you can do in C#, you should be able to do it on @mhosman .

Be careful, C# Eval Library require a valid C# syntax. The or should be replaced by ||.

So probably more something like this:

var list2 = context.EntitySimples.WhereDynamic(x => "EF.Functions.Like(x.ColumnString, \"%bc%\") || id == 1").ToList();

Hello all,

Unfortunately, this request go beyond of what this library can offer.

There is currently no plan adding it on a short time.

However, that is possible with another of our library: https://eval-expression.net/

// Register Type & ExtensionMethod only once
EvalManager.DefaultContext.RegisterType(typeof(EF));
EvalManager.DefaultContext.RegisterExtensionMethod(typeof(DbFunctionsExtensions));

using (var context = new EntityContext())
{
    //var list = context.EntitySimples.Where(x => EF.Functions.Like(x.ColumnString, "%bc%")).ToList();

    var list2 = context.EntitySimples.WhereDynamic(x => "EF.Functions.Like(x.ColumnString, \"%bc%\")").ToList();

   // or

    var list3 = context.EntitySimples.WhereDynamic("x => EF.Functions.Like(x.ColumnString, \"%bc%\")").ToList();
}

The library is paid but Dynamic LINQ extension such as WhereDynamic as free.

You can find some documentation here: https://eval-expression.net/linq-dynamic

Let me know if that solves your issues.

Best Regards,

Jon

To get real SQL Like you need to use the EntityFramework.DynamicLinq or Microsoft.EntityFrameworkCore.DynamicLinq NuGet.

See this for an example: https://github.com/zzzprojects/System.Linq.Dynamic.Core/blob/master/src-console/ConsoleAppEF2.1.1_InMemory/Program.cs#L212