0

Is there any other way to solve this issue? Aside from using .AsExpandable() using Linqkit. Please help if there is another way.

private static IQueryable<Data.BidVehicle> PredicateBuilderQuery(IQueryable<Data.Vehicle> vehicles, List<string> MileAge)
{

    var predicate = PredicateBuilder.True<Data.BidVehicle>();

    foreach (var mpgc in MileAge)
    {
        int[] splitDash = SplitAndTrimDashInt(mpgc);
        int min = splitDash[0];
        int max = splitDash[1];

        predicate = predicate.Or(p => p.IVehicle.Mileage >= min && p.IVehicle.Mileage <= max);

    }

    vehicles= vehicles.Where(predicate);
  //vehicles= vehicles.AsExpandable().Where(predicate);

    return vehicles;
}
DavidG
  • 95,392
  • 10
  • 185
  • 181
  • Possible duplicate of ["The LINQ expression node type 'Invoke' is not supported in LINQ to Entities" - stumped!](https://stackoverflow.com/questions/5284912/the-linq-expression-node-type-invoke-is-not-supported-in-linq-to-entities) – Renat Jul 10 '19 at 08:50
  • Is there a reason you're building a predicate like this instead of just creating a normal `Expression<>`? – DavidG Jul 10 '19 at 08:55
  • @DavidG I'm still new to C# and I'm using Entity Framework for db. I'm trying to build a multiple dynamic query. and PredicateBuilder Class is the only solution I have encountered to solve the issue. Now the code runs fine when I install Linqkit to use the .AsExpandable() . But I'm trying to figure out if is there any solution for me to not install and not use the Linqkit. – Anthony Quartz Jul 10 '19 at 09:01
  • But what are you trying to do here? It's not clear. – DavidG Jul 10 '19 at 09:09
  • I'm trying to do a dynamic OR query. User choose a mileage. Mileage is a list of users choice. I can't do .Where(p => p.IVehicle.Mileage >= min && p.IVehicle.Mileage <= max || p => p.IVehicle.Mileage >= min && p.IVehicle.Mileage <= max). For it is dynamic. Thats why I'm using PredicateBuilder. – Anthony Quartz Jul 10 '19 at 09:18
  • What is `p.IVehicle`? Maybe you should show the entire `Data.BidVehicle` class. – Gert Arnold Jul 10 '19 at 10:26
  • I ran into a similar problem in my Full Outer Join code - it builds expression trees for a full outer join, worked fine in LINQ to SQL, but not with EF. I built an `ExpressionVisitor` that essentially is a limited version of LINQKit's `Invoke`/`Expand` called `Apply` that in-place expands a `LambdaExpression` which you can see [here](https://stackoverflow.com/a/49418695/2557128). Note that this specific `Apply` has special consideration for `null` propagation when `null` is an argument (statically handles `null.member` -> `null` as if it were `null?.member`). – NetMage Jul 10 '19 at 17:28
  • See also [this answer](https://stackoverflow.com/a/6736589/2557128). – NetMage Jul 10 '19 at 17:37

0 Answers0