FSharp.QueryProvider


FSharp.QueryProvider

Modular Linq provider library for .Net. Use it to easily add a Linq provider to your orm.

The FSharp.QueryProvider library can be installed from NuGet:
PM> Install-Package FSharp.QueryProvider

Example

Example for doing a like query against a simple person type.

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
23: 
24: 
25: 
26: 
27: 
28: 
29: 
30: 
31: 
32: 
33: 
34: 
35: 
36: 
37: 
38: 
39: 
40: 
41: 
42: 
43: 
44: 
45: 
46: 
47: 
#I "../../bin"
#r "FSharp.QueryProvider/FSharp.QueryProvider.dll"
open FSharp.QueryProvider.QueryTranslator
open FSharp.QueryProvider.Queryable
open System.Data

let connectionString = "Server=localhost;Database=Northwind;Trusted_Connection=True;"

let queryProvider =
    DBQueryProvider (
        (fun () -> new SqlClient.SqlConnection(connectionString)), 
        (fun connection expression ->
            let command, ctor = 
                translateToCommand 
                    QueryDialect.SqlServer2012 
                    SelectQuery 
                    None 
                    None 
                    None 
                    connection 
                    expression

            let ctor =
                match ctor with
                | Some ctor -> ctor
                | None -> failwith "no ctorinfor generated"
            command :> IDbCommand, ctor), 
        None, 
        None)

type JobKind =
| Salesman = 0
| Manager = 1

type Person =
    { PersonId : int
      PersonName : string
      JobKind : JobKind
      VersionNo : int }

let does = query {
    for p in makeQuery<Person>(queryProvider) do
    where(p.PersonName.Contains "doe")
    select p
}

printfn "%A" (does |> Seq.toList)

Some more info

Samples & documentation

The library comes with comprehensible documentation. It can include tutorials automatically generated from *.fsx files in the content folder. The API reference is automatically generated from Markdown comments in the library implementation.

  • Tutorial contains a further explanation of this sample library.

  • API Reference contains automatically generated documentation for all types, modules and functions in the library. This includes additional brief samples on using most of the functions.

Contributing and copyright

The project is hosted on GitHub where you can report issues, fork the project and submit pull requests. If you're adding a new public API, please also consider adding samples that can be turned into a documentation. You might also want to read the library design notes to understand how it works.

The library is available under Public Domain license, which allows modification and redistribution for both commercial and non-commercial purposes. For more information see the License file in the GitHub repository.

Multiple items
namespace FSharp

--------------------
namespace Microsoft.FSharp
namespace FSharp.QueryProvider
module QueryTranslator

from FSharp.QueryProvider
module Queryable

from FSharp.QueryProvider
namespace System
namespace System.Data
val connectionString : string

Full name: Index.connectionString
val queryProvider : DBQueryProvider<SqlClient.SqlConnection>

Full name: Index.queryProvider
Multiple items
type DBQueryProvider<'T (requires 'T :> IDbConnection)> =
  inherit QueryProvider
  new : getConnection:(unit -> 'T) * translate:('T -> Expression -> IDbCommand * ConstructionInfo) * onExecutingCommand:(IDbCommand -> IDbCommand * obj) option * onExecutedCommand:(IDbCommand * obj -> unit) option -> DBQueryProvider<'T>
  override Execute : expression:Expression -> obj

Full name: FSharp.QueryProvider.Queryable.DBQueryProvider<_>

--------------------
new : getConnection:(unit -> 'T) * translate:('T -> System.Linq.Expressions.Expression -> IDbCommand * FSharp.QueryProvider.DataReader.ConstructionInfo) * onExecutingCommand:(IDbCommand -> IDbCommand * obj) option * onExecutedCommand:(IDbCommand * obj -> unit) option -> DBQueryProvider<'T>
namespace System.Data.SqlClient
Multiple items
type SqlConnection =
  inherit DbConnection
  new : unit -> SqlConnection + 1 overload
  member BeginTransaction : unit -> SqlTransaction + 3 overloads
  member ChangeDatabase : database:string -> unit
  member Close : unit -> unit
  member ConnectionString : string with get, set
  member ConnectionTimeout : int
  member CreateCommand : unit -> SqlCommand
  member DataSource : string
  member Database : string
  member EnlistDistributedTransaction : transaction:ITransaction -> unit
  ...

Full name: System.Data.SqlClient.SqlConnection

--------------------
SqlClient.SqlConnection() : unit
SqlClient.SqlConnection(connectionString: string) : unit
val connection : SqlClient.SqlConnection
val expression : System.Linq.Expressions.Expression
val command : SqlClient.SqlCommand
val ctor : FSharp.QueryProvider.DataReader.ConstructionInfo option
val translateToCommand : queryDialect:QueryDialect -> queryType:QueryType -> getDBType:FSharp.QueryProvider.QueryTranslatorUtilities.GetDBType<FSharp.QueryProvider.SqlDbType> option -> getTableName:FSharp.QueryProvider.QueryTranslatorUtilities.GetTableName option -> getColumnName:FSharp.QueryProvider.QueryTranslatorUtilities.GetColumnName option -> connection:SqlClient.SqlConnection -> expression:System.Linq.Expressions.Expression -> SqlClient.SqlCommand * FSharp.QueryProvider.DataReader.ConstructionInfo option

Full name: FSharp.QueryProvider.QueryTranslator.translateToCommand
type QueryDialect = | SqlServer2012

Full name: FSharp.QueryProvider.QueryTranslator.QueryDialect
union case QueryDialect.SqlServer2012: QueryDialect
union case QueryType.SelectQuery: QueryType
union case Option.None: Option<'T>
val ctor : FSharp.QueryProvider.DataReader.ConstructionInfo
union case Option.Some: Value: 'T -> Option<'T>
val failwith : message:string -> 'T

Full name: Microsoft.FSharp.Core.Operators.failwith
type IDbCommand =
  member Cancel : unit -> unit
  member CommandText : string with get, set
  member CommandTimeout : int with get, set
  member CommandType : CommandType with get, set
  member Connection : IDbConnection with get, set
  member CreateParameter : unit -> IDbDataParameter
  member ExecuteNonQuery : unit -> int
  member ExecuteReader : unit -> IDataReader + 1 overload
  member ExecuteScalar : unit -> obj
  member Parameters : IDataParameterCollection
  ...

Full name: System.Data.IDbCommand
type JobKind =
  | Salesman = 0
  | Manager = 1

Full name: Index.JobKind
JobKind.Salesman: JobKind = 0
JobKind.Manager: JobKind = 1
type Person =
  {PersonId: int;
   PersonName: string;
   JobKind: JobKind;
   VersionNo: int;}

Full name: Index.Person
Person.PersonId: int
Multiple items
val int : value:'T -> int (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.int

--------------------
type int = int32

Full name: Microsoft.FSharp.Core.int

--------------------
type int<'Measure> = int

Full name: Microsoft.FSharp.Core.int<_>
Person.PersonName: string
Multiple items
val string : value:'T -> string

Full name: Microsoft.FSharp.Core.Operators.string

--------------------
type string = System.String

Full name: Microsoft.FSharp.Core.string
Multiple items
Person.JobKind: JobKind

--------------------
type JobKind =
  | Salesman = 0
  | Manager = 1

Full name: Index.JobKind
Person.VersionNo: int
val does : System.Linq.IQueryable<Person>

Full name: Index.does
val query : Linq.QueryBuilder

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.query
val p : Person
val makeQuery : queryProvider:QueryProvider -> System.Linq.IQueryable<'t>

Full name: FSharp.QueryProvider.Queryable.makeQuery
custom operation: where (bool)

Calls Linq.QueryBuilder.Where
System.String.Contains(value: string) : bool
custom operation: select ('Result)

Calls Linq.QueryBuilder.Select
val printfn : format:Printf.TextWriterFormat<'T> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
module Seq

from Microsoft.FSharp.Collections
val toList : source:seq<'T> -> 'T list

Full name: Microsoft.FSharp.Collections.Seq.toList
Fork me on GitHub