0

I am testing the predicateBuilder and I am getting this error

The LINQ expression node type 'Invoke' is not supported in LINQ to Entities. here is my code

 public partial class Product
{
    public static Expression<Func<UserAddress, bool>> IsSelling()
    {
        return p => p.ispeacc == true;
    }
}
public partial class Product
{
    public static Expression<Func<UserAddress, bool>> ContainsInDescription()
    {
        var predicate = PredicateBuilder.New<UserAddress>();

        predicate = predicate.Or(p => p.accNumber == "i****");

        return predicate;
    }
}
public class Accounts
{
    public UserAddress GetAccount()
    {
        var repositoryUAdd = new Repository<UserAddress>();
        var ispor = Product.IsSelling();
        var acc = Product.ContainsInDescription();
        UserAddress accInforesult = repositoryUAdd.GetEntitybybool(ispor.And(acc));

        return accInforesult;

    }
}

public T GetEntitybybool(
      Expression<Func<T, bool>> filter)
    {

        return DbSet.Where(filter).DefaultIfEmpty(null).FirstOrDefault();

    }

Any idea what I am doing wrong

user6272884
  • 101
  • 2
  • 8

1 Answers1

0

The PredicateBuilder class from LinqKit is not directly compatible with EF. So you either switch to another predicate builder library that has no such issues (like Universal PredicateBuilder or my own PredicateUtils class from my answer to Establish a link between two lists in linq to entities where clause), or if you want to stay with LinqKit, then either use Expand custom method on the resulting predicate:

    UserAddress accInforesult = repositoryUAdd.GetEntitybybool(ispor.And(acc).Expand());

or AsExpandable on the query source:

return DbSet.AsExpandable().Where(filter).DefaultIfEmpty(null).FirstOrDefault();
Community
  • 1
  • 1
Ivan Stoev
  • 195,425
  • 15
  • 312
  • 343