开发者

Setting DataLoadOptions for DataContext in F#

开发者 https://www.devze.com 2023-02-18 06:09 出处:网络
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 whic

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).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号