Converting F# Quotations into LINQ Expressions

Posted by forki23 on Stack Overflow See other posts from Stack Overflow or by forki23
Published on 2010-04-21T11:34:57Z Indexed on 2010/04/21 14:53 UTC
Read the original article Hit count: 355

Filed under:
|
|
|

Hi,

I can convert a quotation of type Expr<'a -> 'b> to a Linq expression via the following snippet:

/// Converts a F# Expression to a LINQ Lambda
let toLambda (exp:Expr) =
    let linq = exp.ToLinqExpression() :?> MethodCallExpression
    linq.Arguments.[0] :?> LambdaExpression

/// Converts a Lambda quotation into a Linq Lamba Expression with 1 parameter
let ToLinq (exp : Expr<'a -> 'b>) =
    let lambda = toLambda exp
    Expression.Lambda<Func<'a, 'b>>(lambda.Body, lambda.Parameters)

Now I want to convert a quotation of type Expr<'a * 'b -> 'c> or maybe even Expr<'a -> 'b -> 'c> to a Linq Lambda Expression of type Expression<Func<'a,'b'c>>.

How can I do this?

Regards, forki

© Stack Overflow or respective owner

Related posts about F#

Related posts about c#