You are wrong, and you should avoid Expression.Invoke, my linq spec project does exactly this, and it works. http://linqspecs.codeplex.com/
<http://linqspecs.codeplex.com/>given expr1 and expr2, you can always do this: ParameterExpression param = expr1.Parameters[0];if (ReferenceEquals(param, expr2.Parameters[0])) { return Expression.Lambda<Func<T, bool>>(Expression.AndAlso(expr1.Body, expr2.Body), param); }return Expression.Lambda<Func<T, bool>>(Expression.AndAlso(expr1.Body, Expression.Invoke(expr2, param)), param); See my AndSpecification here: http://linqspecs.codeplex.com/SourceControl/changeset/view/f8b332648229#LinqSpecs%2fAndSpecification.cs <http://linqspecs.codeplex.com/SourceControl/changeset/view/f8b332648229#LinqSpecs%2fAndSpecification.cs> 2011/1/7 Fabian Schmied <[email protected]> > Hi, > > PredicateBuilder uses a neat little trick that is, however, not supported > by NHibernate yet: to fit a LambdaExpression in a place where no > LambdaExpression is allowed, it builds an InvocationExpression around the > LambdaExpression. NHibernate does not evaluate that InvocationExpression. > > I've opened a JIRA issue to solve this at the re-linq level because this is > something all LINQ providers based on re-linq (not only NHibernate) would > benefit from: https://www.re-motion.org/jira/browse/RM-3656. > I can't promise anything, but I'm planning to implement a few new > features for re-linq this January, so this might be working soon in re-linq > - and, after they take over the latest re-linq version, in NHibernate as > well. > > In the meantime, you could use a modified version of PredicateBuilder > (modified from http://www.albahari.com/nutshell/predicatebuilder.aspx): > > public static Expression<Func<T, bool>> And<T> (this Expression<Func<T, > bool>> expr1, > Expression<Func<T, > bool>> expr2) > { > var adaptedExpr2Body = ReplacingExpressionTreeVisitor.Replace > (expr2.Parameters.Single(), expr1.Parameters.Single(), expr2.Body); > return Expression.Lambda<Func<T, bool>> > (Expression.AndAlso (expr1.Body, adaptedExpr2Body), > expr1.Parameters); > } > > (Untested, from my head. ReplacingExpressionTreeVisitor is a part of > re-linq and resides in the Remotion.Data.Linq.Parsing,ExpressionTreeVisitors > namespace.) > "Or" would need to be adapted in a similar fashion. > > Hope this helps, > Fabian > > -- > You received this message because you are subscribed to the Google Groups > "nhusers" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<nhusers%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/nhusers?hl=en. > -- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
