f# - Translating Linq to a FSharp expression -
the documentdb has walk-though , sample project in c# working through in fsharp. 1 of 1st tasks locate existing datbase. c# code this
var database = client.createdatabasequery().where(db => db.id == "familyregistry").toarray().firstordefault();
i attempting same line in fsharp not getting .where though referencing same libraries. instead getting this:
am thinking problem wrong? in advance.
linq isn't specific c#. in c# need add reference system.linq.dll
, using system.linq;
statement. c# project templates include these statements.
in f# need same, ensure project has reference system.linq , add open system.linq
statement
there @ least 2 more idiomatic ways:
you can use seq module's functions pipeline operator achieve same result method chaining, eg:
let random = new system.random() seq.initinfinite (fun _ -> random.next()) |> seq.filter (fun x -> x % 2 = 0) |> seq.take 5 |> seq.iter (fun elem -> printf "%d " elem) printfn ""
seq<'t>
synonym ofienumerable<t>
if apply methods iqueryable force query's execution.you can use query expressions, equivalent linq's sql-like syntax:
let countofstudents = query { student in db.student select student count }
query
returns properiqueryable<t>
your specific query this:
let database = query { db in client.createdatabasequery() db.id == "familyregistry" select db headordefault }
Comments
Post a Comment