29

The Entity Framework does not support the Expression.Invoke operator. You receive the following exception when trying to use it:

"The LINQ expression node type 'Invoke' is not supported in LINQ to Entities.

Has anyone got a workaround for this missing functionality? I would like to use the PredicateBuilder detailed here in an Entity Framework context.

Edit 1 @marxidad - I like your suggestion, however it does baffle me somewhat. Can you give some further advice on your proposed solution?

Edit 2 @marxidad - Thanks for the clarification.

Drew Noakes
  • 300,895
  • 165
  • 679
  • 742
Brad Leach
  • 16,857
  • 17
  • 72
  • 88
  • have a look at the [CLR Method to Canonical Function Mapping](http://msdn.microsoft.com/en-us/library/bb738681.aspx) page on MSDN. – Mark Cidade Aug 19 '08 at 02:48
  • Yeah, looks like Entity Framework doesn't support this, nor could i jerry-rig a way to get it to evaluate in a way that would work. – Darren Kopp Aug 15 '08 at 16:17

2 Answers2

31

PredicateBuilder and LINQKit now support Entity Framework.

Sorry, guys, for not doing this earlier!

Joe Albahari
  • 30,118
  • 7
  • 80
  • 91
  • 6
    Yep- it works now. Just add AsExpandable() before your .Where<>() and your good to go. – Merritt Jun 23 '09 at 18:33
  • 3
    When I add the AsExpandable(), I'm receiving "Unable to cast object of type 'System.Linq.Expressions.MemberExpression' to type 'System.Linq.Expressions.LambdaExpression'." in the VisitInvocation at the line LambdaExpression lambda = (LambdaExpression)target; – mikemurf22 Mar 14 '11 at 16:53
0

The Entity framework converts LINQ expressions into Entity Command trees and within that only its canonical functions are supported. You'd have to use the command trees with canonical functions to do something like PredicateBuilder.

Mark Cidade
  • 98,437
  • 31
  • 224
  • 236