SQLProvider


MySQL Provider

Parameters

ConnectionString

Basic connection string used to connect to MySQL instance; typical connection string parameters apply here. See MySQL Connector/NET Connection Strings Documentation for a complete list of connection string options.

1: 
2: 
[<Literal>]
let connString  = "Server=localhost;Database=HR;User=root;Password=password"

ConnectionStringName

Instead of storing the connection string in the source code, you can store it in the App.config file. This is the name of the connectionString key/value pair stored in App.config (TODO: confirm filename).

1: 
2: 
// found in App.config (TODO: confirm)
let connexStringName = "DefaultConnectionString"

Database Vendor

Use MYSQL from the FSharp.Data.Sql.Common.DatabaseProviderTypes enumeration.

1: 
2: 
[<Literal>]
let dbVendor    = Common.DatabaseProviderTypes.MYSQL

Resolution Path

Path to search for assemblies containing database vendor specific connections and custom types. Type the path where Mysql.Data.dll is stored. Both absolute and relative paths are supported.

1: 
2: 
[<Literal>]
let resPath = __SOURCE_DIRECTORY__ + @"/../../../packages/scripts/MySql.Data/lib/net45"

Individuals Amount

Sets the count of records to load for each table. See individuals for further info.

1: 
2: 
[<Literal>]
let indivAmount = 1000

Use Option Types

If true, F# option types will be used in place of nullable database columns. If false, you will always receive the default value of the column's type even if it is null in the database.

1: 
2: 
[<Literal>]
let useOptTypes = true

Example

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
type sql = SqlDataProvider<
                dbVendor,
                connString,
                ResolutionPath = resPath,
                IndividualsAmount = indivAmount,
                UseOptionTypes = useOptTypes,
                Owner = "HR"
            >
let ctx = sql.GetDataContext()

let employees = 
    ctx.Hr.Employees 
    |> Seq.map (fun e -> e.ColumnValues |> Seq.toList)
    |> Seq.toList

Caveats / Additional Info

Check General, Static Parameters and Querying documentation.

More to be added.

Fork me on GitHub