F# and ADO.NET - idiomatic F#

后端 未结 3 931
星月不相逢
星月不相逢 2021-02-04 01:55

I\'m just starting to learn F#. I wrote this F#/ADO.NET code last night. In what ways would you improve the syntax - make it feel like idiomatic F#?

    let cn =         


        
3条回答
  •  一整个雨季
    2021-02-04 02:27

    I wrote a functional wrapper over ADO.NET for F#. With this library your example looks like this:

    let openConn() =
       let cn = new OleDbConnection(cnstr)
       cn.Open()
       cn :> IDbConnection
    
    let query sql = Sql.execReader (Sql.withNewConnection openConn) sql
    
    let people = query "select * from people" |> List.ofDataReader
    printfn "%d" people.Length
    people |> Seq.iter (fun r -> printfn "%s" (r?LastName).Value)
    

提交回复
热议问题