You must Sign In to post a response.
  • Category: LINQ

    Intercepting internal results of Expression Tree at run-time


    We use Func<T,U,V,...> with Expression Tree to evaluate expression at run time that returns a result, which we can use further.

    In my application, I am using an Expression tree with various nested Expressions. But a scenario occured where I need to intercept an intermediate result of an internal Expression in the Expression Tree. And the moment it is intercepted, it needs to be stored in somewhere for logging purpose and after that the Expression Tree should continue to execute further.

    In order words, can I call a Custom Helper method from an Expression of Expression Tree along with intermediate data?

    Please let me know if this can be achieved from Expression Tree. If so, how?

    ** Incase an answer is already available in the forum, please let me know.

  • #760685
    You can use 'into' keyword to store intermediate data of linq
    var em = from e in employee
    group e by new{ e.DeptId}
    into groupemployee
    where groupemployee.Count() > 1
    select new { groupemployee.Key.DeptId, salary = groupemployee.Sum(t => t.Salary) };

    also you can use 'let' keyword to do operation

  • #761878
    Thanks Umesh.

  • Sign In to post your comments