Setting DataLoadOptions for DataContext in F#
Is it possible to set the DataLoadOptions on a data context in F#? S开发者_JAVA技巧o far I have had no luck because the DataLoadOptions.LoadWith() takes a System.Linq.Expressions.LambdaExpression which seems impossible to instantiate in F#
I believe this should be possible. You'll need to reference FSharp.PowerPack.Linq.dll
which adds support for translating F# quotations (written using <@ fun x -> x.Foo @>
) to C# expression trees. Something like this should do the trick:
#r @"FSharp.PowerPack.Linq.dll"
open System
open System.Linq.Expressions
open Microsoft.FSharp.Linq.QuotationEvaluation
let e = <@ Func<int, int>(fun x -> 1 + x) @>
let lambda = e.ToLinqExpression() :?> LambdaExpression
Note that the quotation creates a Func<...>
delegate, which is translated to expression tree that can be converted to LambdaExpression
(normal F# functions are represented differently).
精彩评论