System.Linq.Dynamic.Core.DynamicExpressionParser.ParseLambda 投掷 System.NotSupportedException

System.Linq.Dynamic.Core.DynamicExpressionParser.ParseLambda throwing System.NotSupportedException

正在尝试使用 System.Linq.Dynamic.Core 库中可用的 ParseLmabda 方法。当我执行以下简单示例时。

using (var context = new EntityContext())
{
    Expression<Func<Customer, bool>> e1 = System.Linq.Dynamic.Core.DynamicExpressionParser
        .ParseLambda<Customer, bool>(null, true, "City = @0", "London");

    var customers = context.Customers.Where("@0(it)", e1).ToList();

}

它抛出以下异常。

System.NotSupportedException: 'The LINQ expression node type 'Invoke' is not supported in LINQ to Entities.'

知道我做错了什么吗?

您是否尝试过此代码:

Expression<Func<Customer, bool>> e1 = DynamicExpressionParser.ParseLambda<Customer, bool>(null, true, "City = @0", "London");

var customers = Customers.Where(e1).ToList();

更新 (2020-06-01)

实际上,下面的代码应该可以正常工作。

var e1 = DynamicExpressionParser.ParseLambda<Customer, bool>(new ParsingConfig(), true, "City = @0", "London");
var e2 = DynamicExpressionParser.ParseLambda<Customer, bool>(new ParsingConfig(), true, "c => c.CompanyName != \"test\"");

var customers = context.Customers.ToList().AsQueryable().Where("@0(it) and @1(it)", e1, e2);

参见示例:https://dotnetfiddle.net/PF9Htk