-1

I have this code:

public static bool ContainEx<T>(this IQueryable<T> query, System.Linq.Expressions.Expression<System.Func<T, bool>> expression)
{
    return query.Any(expression);
}

If I use that:

return bonusesWhereSearch.WhereEx(x => userBonusesWhereSearch.ContainEx(y => y.Bonus_Id == x.Id));

I get this error message:

System.NotSupportedException: LINQ to Entities does not recognize the method 'Boolean ContainEx[Bonus](System.Linq.IQueryable`1[SDataEntities.Bonus], System.Linq.Expressions.Expression`1[System.Func`2[SDataEntities.Bonus,System.Boolean]])' method, and this method cannot be translated into a store expression.

and if I use Any:

return bonusesWhereSearch.WhereEx(x => userBonusesWhereSearch.Any(y => y.Bonus_Id == x.Id));

that does work.

Glebka
  • 1,420
  • 3
  • 20
  • 37

1 Answers1

1

Problem here is, that entity framework doesn't execute ContainEx, but tries to translate this method into SQL. And since this is custom method translation fails. If you use Any directly, it is correctly translated to SQL equivalent.

Marian Polacek
  • 2,906
  • 4
  • 30
  • 37