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:

enter image description here

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:

  1. 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 of ienumerable<t> if apply methods iqueryable force query's execution.

  2. you can use query expressions, equivalent linq's sql-like syntax:

    let countofstudents =     query {         student in db.student         select student         count     } 

    query returns proper iqueryable<t>

your specific query this:

let database =       query {         db in client.createdatabasequery()         db.id == "familyregistry"         select db         headordefault     } 

Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -