SqlCommand.AsyncMethods

namespace Foo

[<AutoOpen>]
module FsDataEx =

    type System.Data.SqlClient.SqlCommand with
        member this.AsyncExecuteNonQuery =
            Async.FromBeginEnd(this.BeginExecuteNonQuery, this.EndExecuteNonQuery)

        member this.AsyncExecuteReader() =
            Async.FromBeginEnd(this.BeginExecuteReader, this.EndExecuteReader)

        member this.AsyncExecuteReader(behavior : System.Data.CommandBehavior) =
            Async.FromBeginEnd((fun (cb, state) -> this.BeginExecuteReader(cb, state, behavior)), this.EndExecuteReader)

        member this.AsyncExecuteXmlReader() =
            Async.FromBeginEnd(this.BeginExecuteXmlReader, this.EndExecuteXmlReader)
Example:
async {
    use! reader = someCommand.AsyncExecuteReader()
    // do stuff with reader
}

Description

A set of extension methods to allow asynchronous SqlClient operations to integrate with F# async workflows.

Details

Double click on the code to select all.

 

;