问题
I'm parameterizing some linq queries, and ended up using dynamic linq. Initially I had some trouble extracting the data from the dynamic objects it created but I managed to extract it using FSharp. InteropDynamic, regarding a better way to parameterize linq queries I plan to post another question. My question is .
- Is this the best way to access dynamic linq and/or dynamic objects (memory and speed wise?).
When I first use it FSI gives me a message.
Binding session to '..\..\packages\Dynamitey.1.0.2.0\lib\net40\Dynamitey.dll'...
What is this exactly?
Simplified code:
#if INTERACTIVE
#r "System.Data.Linq.dll"
#r @"..\packages\System.Linq.Dynamic.1.0.6\lib\net4\System.Linq.Dynamic.dll"
#r @"..\packages\FSharp.Interop.Dynamic.3.0.0.0\lib\portable-net45+sl50+win\FSharp.Interop.Dynamic.dll"
#r @"..\packages\Dynamitey.1.0.2.0\lib\net40\Dynamitey.dll"
#endif
open System.Linq
open System.Linq.Dynamic
open FSharp.Interop.Dynamic
type Rec1 = {
City:string
Country:string
Zip:int
}
let x = [{City="London";Country="UK";Zip=1029};{City="Glasgow";Country="UK";Zip=30921};
{City="London";Country="USA";Zip=90210}]
let y = x.Where(fun x -> x.City ="London").Select("new(City,Zip)")
[for xx in y -> (xx?City:string),(xx?Zip:int)]
This will give me: val it : (string * int) list = [("London", 1029); ("London", 90210)]
as expected.
This is a good overview of using dynamic objects from F#: F# dynamic object access
来源:https://stackoverflow.com/questions/36539639/accessing-dynamic-objects-in-f