LINQ Parametric Query

This is another challenge to access dynamic objects in F # . I use let y = x.Where(fun x -> x.City ="London").Select("new(City,Zip)") to parameterize the query and retrieve the necessary elements. They will correspond to the columns in the SQL query and will be represented by the datacontext property. This is the part that I would like to pass as a parameter.

 type Northwind = ODataService<"http://services.odata.org/Northwind/Northwind.svc"> let db = Northwind.GetDataContext() let query2 = query { for customer in db.Customers do select customer} |> Seq.toArray let qryfun (x:Northwind.ServiceTypes.Customer) = query { for x in query2 do select (x.City,x.CompanyName,x.Country)} 

Basically, I would like to go through not only x , but also x.* . Since I am accessing one database that is fixed, I can split x. However, now I have 40 small functions that extract different columns. Is it possible to include it in one function and pass the property as an argument? So sometimes I extract x.City , but sometimes x.Country . I tried using quotes, however I can't splic it correctly, and maybe this is the wrong approach.

+6
source share
1 answer

As for splicing quotes, this works for me:

 open System.Linq type record = { x:int; y:string } let mkQuery q = query { for x in [{x=1;y="test"}].AsQueryable() do select ((%q) x) } mkQuery <@ fun r -> rx, ry @> |> Seq.iter (printfn "%A") 
+7
source

All Articles