Lambda Expression RRS feed

  • Question

  • How does Expression.Call( work?

    I keep getting, "No method 'Any' on type 'System.Linq.Queryable' is compatible with the supplied arguments.", and I am unsure on how to resolve this.

    I have 2 entities, Foo and Bar, Foo has a navigation property to its children, Bar.

    I have two functions, an inner and an outer:
    Expression<Func<Bar, bool>> barFunction = b => b.SomeField == "Some Value"; 

    ParameterExpression fooParameter = Expression.Parameter(typeof(Foo), "f"); 
    Expression fooExpression = Expression.Lambda( 

    This gives me, f => f.Bar

    What I want is:
    f => f.Bar.Any(b => b.SomeField == "Some Value");

    I have the inner, and I have the outer, now I just need to chain them with the Any method, I hope.

    The fun part:
    Expression any = Expression.Call( 
        new Type[] { innerFunction.Type }, 

    the type should be "Bar, bool", which is the signiture of the innerFunction, is passing the Type of the Function here correct?
    What should be passed as parameters?

    Thank you

    Monday, January 12, 2009 3:43 PM