FSharpComposableQuery


Lots of sample queries

This file collects the sample queries from the Visual Studio documentation for F#. The original queries can be found here:

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
#r "FSharp.Data.TypeProviders.dll"
#r "System.Data.dll"
#r "System.Data.Linq.dll"
#r "FSharp.PowerPack.Linq.dll"
#r "FSharpComposableQuery.dll"

open System
open System.Data.Linq.SqlClient
open System.Linq

open Microsoft.FSharp.Data.TypeProviders
open Microsoft.FSharp.Linq

open FSharpComposableQuery

Query examples

We assume a locally configured SQL Srever database server with the database MyDatabase populated as shown on this page. All of the queries run correctly with FSharpComposableQuery and produce the same answers as the main implementation of F# query. This is because FSharpComposableQuery leaves query operations it doesn't recognize in place.

 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: 
[<Literal>]
let ConnectionString = 
  "Data Source=(localdb)\MyInstance;\
   Initial Catalog=MyDatabase;
   Integrated Security=SSPI"

type schema = SqlDataConnection<ConnectionString>

let db = schema.GetDataContext()
//db.DataContext.Log <- System.Console.Out

let student = db.Student

let data = [1; 5; 7; 11; 18; 21]

type Nullable<'T when 'T : ( new : unit -> 'T) and 'T : struct and 'T :> ValueType > with
    member this.Print() =
        if (this.HasValue) then this.Value.ToString()
        else "NULL"

let testQuery f = f query query

// Convenience copies of failing tests


// Start

contains query operator

1: 
2: 
3: 
4: 
5: 
query {
        for student in db.Student do
        select student.Age.Value
        contains 11
        }|> printfn "Is at least one student age 11? %b" 

count query operator

1: 
2: 
3: 
4: 
5: 
query {
        for student in db.Student do
        select student
        count
        } |> printfn "Number of students: %d" 

last query operator.

1: 
2: 
3: 
4: 
5: 
6: 
query {
        for s in data do
        sortBy s
        last
        } 
|> printfn "Last: %d" 

lastOrDefault query operator.

1: 
2: 
3: 
4: 
5: 
6: 
query {
            for number in data do
            sortBy number
            lastOrDefault
            }  
|> printfn "lastOrDefault: %d"

exactlyOne query operator

1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
let student2 =
    query {
        for student in db.Student do
        where (student.StudentID = 1)
        select student
        exactlyOne
        }
printfn "Student with StudentID = 1 is %s" student2.Name

exactlyOneOrDefault query operator

1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
let student3 =
    query {
        for student in db.Student do
        where (student.StudentID = 1)
        select student
        exactlyOneOrDefault
        }
printfn "Student with StudentID = 1 is %s" student3.Name

headOrDefault query operator

1: 
2: 
3: 
4: 
5: 
6: 
7: 
let student4 =
    query {
        for student in db.Student do
        select student
        headOrDefault
        }
printfn "head student is %s" student4.Name

select query operator

1: 
2: 
3: 
4: 
5: 
query {
        for (student:schema.ServiceTypes.Student) in db.Student do
        select student
        }
|> Seq.iter (fun (student:schema.ServiceTypes.Student) -> printfn "StudentID, Name: %d %s" student.StudentID student.Name)

where query operator

1: 
2: 
3: 
4: 
5: 
6: 
query {
        for student in db.Student do
        where (student.StudentID > 4)
        select student
        }
|> Seq.iter (fun student -> printfn "StudentID, Name: %d %s" student.StudentID student.Name)

minBy query operator

1: 
2: 
3: 
4: 
5: 
let student5 =
    query {
        for student in db.Student do
        minBy student.StudentID
    }

maxBy query operator

1: 
2: 
3: 
4: 
5: 
6: 
let student6 =
    query {
        for student in db.Student do
        maxBy student.StudentID
    }
    

groupBy query operator.

1: 
2: 
3: 
4: 
5: 
6: 
query {
    for student in db.Student do
    groupBy student.Age into g
    select (g.Key, g.Count())
    }
|> Seq.iter (fun (age, count) -> printfn "Age: %s Count at that age: %d" (age.Print()) count)

sortBy query operator

1: 
2: 
3: 
4: 
5: 
6: 
query {
    for student in db.Student do
    sortBy student.Name
    select student
}
|> Seq.iter (fun student -> printfn "StudentID, Name: %d %s" student.StudentID student.Name)

sortByDescending query operator

1: 
2: 
3: 
4: 
5: 
6: 
query {
    for student in db.Student do
    sortByDescending student.Name
    select student
}
|> Seq.iter (fun student -> printfn "StudentID, Name: %d %s" student.StudentID student.Name)

thenBy query operator

1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
query {
    for student in db.Student do
    where student.Age.HasValue
    sortBy student.Age.Value
    thenBy student.Name
    select student
}
|> Seq.iter (fun student -> printfn "StudentID, Name: %d %s" student.Age.Value student.Name)

thenByDescending query operator

1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
query {
    for student in db.Student do
    where student.Age.HasValue
    sortBy student.Age.Value
    thenByDescending student.Name
    select student
}
|> Seq.iter (fun student -> printfn "StudentID, Name: %d %s" student.Age.Value student.Name)

groupValBy query operator

1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
query {
    for student in db.Student do
    groupValBy student.Name student.Age into g
    select (g, g.Key, g.Count())
    }
|> Seq.iter (fun (group, age, count) ->
    printfn "Age: %s Count at that age: %d" (age.Print()) count
    group |> Seq.iter (fun name -> printfn "Name: %s" name))

sumByNullable query operator

1: 
2: 
3: 
4: 
5: 
query {
    for student in db.Student do
    sumByNullable student.Age
    }
|> (fun sum -> printfn "Sum of ages: %s" (sum.Print()))

minByNullable

1: 
2: 
3: 
4: 
5: 
query {
    for student in db.Student do
    minByNullable student.Age
    }
|> (fun age -> printfn "Minimum age: %s" (age.Print()))

maxByNullable

1: 
2: 
3: 
4: 
5: 
query {
    for student in db.Student do
    maxByNullable student.Age
    }
|> (fun age -> printfn "Maximum age: %s" (age.Print()))

averageBy

1: 
2: 
3: 
4: 
5: 
query {
    for student in db.Student do
    averageBy (float student.StudentID)
    }
|> printfn "Average student ID: %f"

averageByNullable

1: 
2: 
3: 
4: 
5: 
query {
    for student in db.Student do
    averageByNullable (Nullable.float student.Age)
    }
|> (fun avg -> printfn "Average age: %s" (avg.Print()))

find query operator

1: 
2: 
3: 
4: 
5: 
query {
    for student in db.Student do
    find (student.Name = "Abercrombie, Kim")
}
|> (fun student -> printfn "Found a match with StudentID = %d" student.StudentID)

all query operator

1: 
2: 
3: 
4: 
5: 
query {
    for student in db.Student do
    all (SqlMethods.Like(student.Name, "%,%"))
}
|> printfn "Do all students have a comma in the name? %b"

head query operator

1: 
2: 
3: 
4: 
5: 
query {
    for student in db.Student do
    head
    }
|> (fun student -> printfn "Found the head student with StudentID = %d" student.StudentID)

nth query operator

1: 
2: 
3: 
4: 
5: 
query {
    for numbers in data do
    nth 3
    }
|> printfn "Third number is %d"

skip query operator

1: 
2: 
3: 
4: 
5: 
query {
    for student in db.Student do
    skip 1
    }
|> Seq.iter (fun student -> printfn "StudentID = %d" student.StudentID)

skipWhile query operator

1: 
2: 
3: 
4: 
5: 
6: 
query {
    for number in data do
    skipWhile (number < 3)
    select number
    }
|> Seq.iter (fun number -> printfn "Number = %d" number)

sumBy query operator

1: 
2: 
3: 
4: 
5: 
query {
   for student in db.Student do
   sumBy student.StudentID
   }
|> printfn "Sum of student IDs: %d" 

take query operator

1: 
2: 
3: 
4: 
5: 
6: 
query {
   for student in db.Student do
   select student
   take 2
   }
|> Seq.iter (fun student -> printfn "StudentID = %d" student.StudentID)

takeWhile query operator

1: 
2: 
3: 
4: 
5: 
query {
    for number in data do
    takeWhile (number < 10)
    }
|> Seq.iter (fun number -> printfn "Number = %d" number)

sortByNullable query operator

1: 
2: 
3: 
4: 
5: 
6: 
7: 
query {
    for student in db.Student do
    sortByNullable student.Age
    select student
}
|> Seq.iter (fun student ->
    printfn "StudentID, Name, Age: %d %s %s" student.StudentID student.Name (student.Age.Print()))

sortByNullableDescending query operator

1: 
2: 
3: 
4: 
5: 
6: 
7: 
query {
    for student in db.Student do
    sortByNullableDescending student.Age
    select student
}
|> Seq.iter (fun student ->
    printfn "StudentID, Name, Age: %d %s %s" student.StudentID student.Name (student.Age.Print()))

thenByNullable query operator

1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
query {
    for student in db.Student do
    sortBy student.Name
    thenByNullable student.Age
    select student
}
|> Seq.iter (fun student ->
    printfn "StudentID, Name, Age: %d %s %s" student.StudentID student.Name (student.Age.Print()))

thenByNullableDescending query operator

1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
query {
    for student in db.Student do
    sortBy student.Name
    thenByNullableDescending student.Age
    select student
}
|> Seq.iter (fun student ->
    printfn "StudentID, Name, Age: %d %s %s" student.StudentID student.Name (student.Age.Print()))

All students:

1: 
2: 
3: 
4: 
5: 
query {
        for student in db.Student do
        select student
    }
    |> Seq.iter (fun student -> printfn "%s %d %s" student.Name student.StudentID (student.Age.Print()))

Count of students:

1: 
2: 
3: 
4: 
5: 
query {
        for student in db.Student do        
        count
    }
|>  (fun count -> printfn "Student count: %d" count)

Exists

1: 
2: 
3: 
4: 
5: 
6: 
7: 
query {
        for student in db.Student do
        where (ExtraTopLevelOperators.query 
                      { for courseSelection in db.CourseSelection do
                        exists (courseSelection.StudentID = student.StudentID) })
        select student }
|> Seq.iter (fun student -> printfn "%A" student.Name)

Group by age and count

1: 
2: 
3: 
4: 
5: 
6: 
query {
        for n in db.Student do
        groupBy n.Age into g
        select (g.Key, g.Count())
}
|> Seq.iter (fun (age, count) -> printfn "%s %d" (age.Print()) count)

Group value by age

1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
9: 
query {
        for n in db.Student do
        groupValBy n.Age n.Age into g
        select (g.Key, g.Count())
    }
|> Seq.iter (fun (age, count) -> printfn "%s %d" (age.Print()) count)


    

Group students by age where age > 10

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
query {
        for student in db.Student do
        groupBy student.Age into g
        where (g.Key.HasValue && g.Key.Value > 10)
        select (g, g.Key)
}
|> Seq.iter (fun (students, age) ->
    printfn "Age: %s" (age.Value.ToString())
    students
    |> Seq.iter (fun student -> printfn "%s" student.Name))

Group students by age and print counts of number of students at each age with more than 1 student

1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
query {
        for student in db.Student do
        groupBy student.Age into group
        where (group.Count() > 1)
        select (group.Key, group.Count())
}
|> Seq.iter (fun (age, ageCount) ->
     printfn "Age: %s Count: %d" (age.Print()) ageCount)

Group students by age and sum ages

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
query {
        for student in db.Student do
        groupBy student.Age into g        
        let total = query { for student in g do sumByNullable student.Age }
        select (g.Key, g.Count(), total)
}
|> Seq.iter (fun (age, count, total) ->
    printfn "Age: %d" (age.GetValueOrDefault())
    printfn "Count: %d" count
    printfn "Total years: %s" (total.ToString()))

Group students by age and count number of students at each age, and display all with count > 1 in descending order of count

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
query {
        for student in db.Student do
        groupBy student.Age into g
        where (g.Count() > 1)        
        sortByDescending (g.Count())
        select (g.Key, g.Count())
}
|> Seq.iter (fun (age, myCount) ->
    printfn "Age: %s" (age.Print())
    printfn "Count: %d" myCount)

Select students from a set of IDs

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
let idList = [1; 2; 5; 10]
let idQuery = query { for id in idList do
                       select id }
query {
        for student in db.Student do
        where (idQuery.Contains(student.StudentID))
        select student
        }
|> Seq.iter (fun student ->
    printfn "Name: %s" student.Name)

Look for students with Name match _e%% pattern and take first two

1: 
2: 
3: 
4: 
5: 
6: 
7: 
query {
    for student in db.Student do
    where (SqlMethods.Like( student.Name, "_e%") )
    select student
    take 2   
    }
|> Seq.iter (fun student -> printfn "%s" student.Name)

Look for students with Name matching [abc]%% pattern

1: 
2: 
3: 
4: 
5: 
6: 
query {
    for student in db.Student do
    where (SqlMethods.Like( student.Name, "[abc]%") )
    select student  
    }
|> Seq.iter (fun student -> printfn "%s" student.Name)

Look for students with name matching [^abc]%% pattern

1: 
2: 
3: 
4: 
5: 
6: 
query {
    for student in db.Student do
    where (SqlMethods.Like( student.Name, "[^abc]%") )
    select student  
    }
|> Seq.iter (fun student -> printfn "%s" student.Name)

Look for students with name matching [^abc]%% pattern and select ID

1: 
2: 
3: 
4: 
5: 
6: 
query {
    for n in db.Student do
    where (SqlMethods.Like( n.Name, "[^abc]%") )
    select n.StudentID    
    }
|> Seq.iter (fun id -> printfn "%d" id)

Using Contains as a query filter

1: 
2: 
3: 
4: 
5: 
6: 
query {
        for student in db.Student do
        where (student.Name.Contains("a"))
        select student
    }
|> Seq.iter (fun student -> printfn "%s" student.Name)

Searching for names from a list

1: 
2: 
3: 
4: 
5: 
let names = [|"a";"b";"c"|]
query {
    for student in db.Student do
    if names.Contains (student.Name) then select student }
|> Seq.iter (fun student -> printfn "%s" student.Name)

Join Student and CourseSelection tables

1: 
2: 
3: 
4: 
5: 
6: 
7: 
query {
        for student in db.Student do 
        join selection in db.CourseSelection 
          on (student.StudentID = selection.StudentID)
        select (student, selection)
    }
|> Seq.iter (fun (student, selection) -> printfn "%d %s %d" student.StudentID student.Name selection.CourseID)

Left Join Student and CourseSelection tables

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
query {
    for student in db.Student do
    leftOuterJoin selection in db.CourseSelection 
      on (student.StudentID = selection.StudentID) into result
    for selection in result.DefaultIfEmpty() do
    select (student, selection)
    }
|> Seq.iter (fun (student, selection) ->
    let selectionID, studentID, courseID =
        match selection with
        | null -> "NULL", "NULL", "NULL"
        | sel -> (sel.ID.ToString(), sel.StudentID.ToString(), sel.CourseID.ToString())
    printfn "%d %s %d %s %s %s" student.StudentID student.Name (student.Age.GetValueOrDefault()) selectionID studentID courseID)

Join with count

1: 
2: 
3: 
4: 
5: 
6: 
query {
        for n in db.Student do 
        join e in db.CourseSelection on (n.StudentID = e.StudentID)
        count        
    }
|>  printfn "%d"

Join with distinct

1: 
2: 
3: 
4: 
5: 
6: 
query {
        for student in db.Student do 
        join selection in db.CourseSelection on (student.StudentID = selection.StudentID)
        distinct        
    }
|> Seq.iter (fun (student, selection) -> printfn "%s %d" student.Name selection.CourseID)

Join with distinct and count

1: 
2: 
3: 
4: 
5: 
6: 
7: 
query {
        for n in db.Student do 
        join e in db.CourseSelection on (n.StudentID = e.StudentID)
        distinct
        count       
    }
|> printfn "%d"

Selecting students with age between 10 and 15

1: 
2: 
3: 
4: 
5: 
6: 
query {
        for student in db.Student do
        where (student.Age.Value >= 10 && student.Age.Value < 15)
        select student
    }
|> Seq.iter (fun student -> printfn "%s" student.Name)

Selecting students with age either 11 or 12

1: 
2: 
3: 
4: 
5: 
6: 
query {
        for student in db.Student do
        where (student.Age.Value = 11 || student.Age.Value = 12)
        select student
    }
|> Seq.iter (fun student -> printfn "%s" student.Name)

Selecting students in a certain age range and sorting

1: 
2: 
3: 
4: 
5: 
6: 
7: 
query {
        for n in db.Student do
        where (n.Age.Value = 12 || n.Age.Value = 13)
        sortByNullableDescending n.Age
        select n
    }
|> Seq.iter (fun student -> printfn "%s %s" student.Name (student.Age.Print()))

Selecting students with certain ages, taking account of possibility of nulls

1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
9: 
query {
        for student in db.Student do
        where ((student.Age.HasValue && student.Age.Value = 11) ||
               (student.Age.HasValue && student.Age.Value = 12))
        sortByDescending student.Name 
        select student.Name
        take 2
    }
|> Seq.iter (fun name -> printfn "%s" name)

Union of two queries

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
module Queries =
    let query1 = query {
            for n in db.Student do
            select (n.Name, n.Age)
        }

    let query2 = query {
            for n in db.LastStudent do
            select (n.Name, n.Age)
            }

    query2.Union (query1)
    |> Seq.iter (fun (name, age) -> printfn "%s %s" name (age.Print()))

Intersect of two queries

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
module Queries2 =
    let query1 = query {
           for n in db.Student do
           select (n.Name, n.Age)
        }

    let query2 = query {
            for n in db.LastStudent do
            select (n.Name, n.Age)
            }

    query1.Intersect(query2)
    |> Seq.iter (fun (name, age) -> printfn "%s %s" name (age.Print()))

Using if statement to alter results for special value

1: 
2: 
3: 
4: 
5: 
6: 
7: 
query {
        for student in db.Student do
        select (if student.Age.HasValue && student.Age.Value = -1 then
                   (student.StudentID, System.Nullable<int>(100), student.Age)
                else (student.StudentID, student.Age, student.Age))
    }
|> Seq.iter (fun (id, value, age) -> printfn "%d %s %s" id (value.Print()) (age.Print()))

Using if statement to alter results special values

1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
9: 
query {
        for student in db.Student do
        select (if student.Age.HasValue && student.Age.Value = -1 then
                   (student.StudentID, System.Nullable<int>(100), student.Age)
                elif student.Age.HasValue && student.Age.Value = 0 then
                    (student.StudentID, System.Nullable<int>(100), student.Age)
                else (student.StudentID, student.Age, student.Age))
    }
|> Seq.iter (fun (id, value, age) -> printfn "%d %s %s" id (value.Print()) (age.Print()))

Multiple table select

1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
query {
        for student in db.Student do
        for course in db.Course do
        select (student, course)
}
|> Seq.iteri (fun index (student, course) ->
    if (index = 0) then printfn "StudentID Name Age CourseID CourseName"
    printfn "%d %s %s %d %s" student.StudentID student.Name (student.Age.Print()) course.CourseID course.CourseName)

Multiple Joins

1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
9: 
query {
    for student in db.Student do
    join courseSelection in db.CourseSelection on
        (student.StudentID = courseSelection.StudentID)
    join course in db.Course on
          (courseSelection.CourseID = course.CourseID)
    select (student.Name, course.CourseName)
    }
    |> Seq.iter (fun (studentName, courseName) -> printfn "%s %s" studentName courseName)

Multiple Left Outer Joins

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
query {
    for student in db.Student do
    leftOuterJoin courseSelection in db.CourseSelection 
      on (student.StudentID = courseSelection.StudentID) into g1
    for courseSelection in g1.DefaultIfEmpty() do
    leftOuterJoin course in db.Course 
      on (courseSelection.CourseID = course.CourseID) into g2
    for course in g2.DefaultIfEmpty() do
    select (student.Name, course.CourseName)
    }
|> Seq.iter (fun (studentName, courseName) -> printfn "%s %s" studentName courseName)
namespace System
namespace System.Data
namespace System.Data.Linq
namespace System.Data.Linq.SqlClient
namespace System.Linq
namespace Microsoft
namespace Microsoft.FSharp
namespace Microsoft.FSharp.Data
namespace Microsoft.FSharp.Data.TypeProviders
namespace Microsoft.FSharp.Linq
namespace FSharpComposableQuery
Multiple items
type LiteralAttribute =
  inherit Attribute
  new : unit -> LiteralAttribute

Full name: Microsoft.FSharp.Core.LiteralAttribute

--------------------
new : unit -> LiteralAttribute
val ConnectionString : string

Full name: QueryExamples.ConnectionString
type schema =
  static member GetDataContext : unit -> MyDatabase + 1 overload
  nested type ServiceTypes

Full name: QueryExamples.schema


<summary>Provides the types to access a database, using a LINQ-to-SQL mapping</summary><param name='ConnectionString'>The connection string for the database connection. If using Visual Studio, a connection string can be found in database properties in the Server Explorer window.</param><param name='ConnectionStringName'>The name of the connection string for the database connection in the configuration file.</param><param name='LocalSchemaFile'>The local .dbml file for the database schema (default: no local schema file)</param><param name='ForceUpdate'>Require that a direct connection to the database be available at design-time and force the refresh of the local schema file (default: true)</param><param name='Pluralize'>Automatically pluralize or singularize class and member names using English language rules (default: false)</param><param name='Views'>Extract database views (default: true)</param><param name='Functions'>Extract database functions (default: true)</param><param name='ConfigFile'>The name of the configuration file used for connection strings (default: app.config or web.config is used)</param><param name='DataDirectory'>The name of the data directory, used to replace |DataDirectory| in connection strings (default: the project or script directory)</param><param name='ResolutionFolder'>The folder used to resolve relative file paths at compile-time (default: folder containing the project or script)</param><param name='StoredProcedures'>Extract stored procedures (default: true)</param><param name='Timeout'>Timeout value in seconds to use when SqlMetal accesses the database (default: 0, which means infinite)</param><param name='ContextTypeName'>The name of data context class (default: derived from database name)</param><param name='Serializable'>Generate uni-directional serializable classes (default: false, which means no serialization)</param>
type SqlDataConnection

Full name: Microsoft.FSharp.Data.TypeProviders.SqlDataConnection


<summary>Provides the types to access a database, using a LINQ-to-SQL mapping</summary><param name='ConnectionString'>The connection string for the database connection. If using Visual Studio, a connection string can be found in database properties in the Server Explorer window.</param><param name='ConnectionStringName'>The name of the connection string for the database connection in the configuration file.</param><param name='LocalSchemaFile'>The local .dbml file for the database schema (default: no local schema file)</param><param name='ForceUpdate'>Require that a direct connection to the database be available at design-time and force the refresh of the local schema file (default: true)</param><param name='Pluralize'>Automatically pluralize or singularize class and member names using English language rules (default: false)</param><param name='Views'>Extract database views (default: true)</param><param name='Functions'>Extract database functions (default: true)</param><param name='ConfigFile'>The name of the configuration file used for connection strings (default: app.config or web.config is used)</param><param name='DataDirectory'>The name of the data directory, used to replace |DataDirectory| in connection strings (default: the project or script directory)</param><param name='ResolutionFolder'>The folder used to resolve relative file paths at compile-time (default: folder containing the project or script)</param><param name='StoredProcedures'>Extract stored procedures (default: true)</param><param name='Timeout'>Timeout value in seconds to use when SqlMetal accesses the database (default: 0, which means infinite)</param><param name='ContextTypeName'>The name of data context class (default: derived from database name)</param><param name='Serializable'>Generate uni-directional serializable classes (default: false, which means no serialization)</param>
val db : schema.ServiceTypes.SimpleDataContextTypes.MyDatabase

Full name: QueryExamples.db
schema.GetDataContext() : schema.ServiceTypes.SimpleDataContextTypes.MyDatabase


Get a simplified data context for this SQL connection. By default, no credentials are set

schema.GetDataContext(connectionString: string) : schema.ServiceTypes.SimpleDataContextTypes.MyDatabase


Get a simplified data context for this SQL connection. By default, no credentials are set
val student : Data.Linq.Table<schema.ServiceTypes.Student>

Full name: QueryExamples.student
property schema.ServiceTypes.SimpleDataContextTypes.MyDatabase.Student: Data.Linq.Table<schema.ServiceTypes.Student>


Gets the 'Student' entities from the SQL connection. This property may be used as the source in a query expression.
val data : int list

Full name: QueryExamples.data
Multiple items
type Nullable =
  static member Compare<'T> : n1:Nullable<'T> * n2:Nullable<'T> -> int
  static member Equals<'T> : n1:Nullable<'T> * n2:Nullable<'T> -> bool
  static member GetUnderlyingType : nullableType:Type -> Type

Full name: System.Nullable

--------------------
type Nullable<'T (requires default constructor and value type and 'T :> ValueType)> =
  struct
    new : value:'T -> Nullable<'T>
    member Equals : other:obj -> bool
    member GetHashCode : unit -> int
    member GetValueOrDefault : unit -> 'T + 1 overload
    member HasValue : bool
    member ToString : unit -> string
    member Value : 'T
  end

Full name: System.Nullable<_>

--------------------
Nullable()
Nullable(value: 'T) : unit
type unit = Unit

Full name: Microsoft.FSharp.Core.unit
type ValueType =
  member Equals : obj:obj -> bool
  member GetHashCode : unit -> int
  member ToString : unit -> string

Full name: System.ValueType
val this : Nullable<'T> (requires default constructor and value type and 'T :> ValueType)
member Nullable.Print : unit -> string

Full name: QueryExamples.Print
property Nullable.HasValue: bool
property Nullable.Value: 'T
ValueType.ToString() : string
val testQuery : f:(QueryImpl.QueryBuilder -> QueryImpl.QueryBuilder -> 'a) -> 'a

Full name: QueryExamples.testQuery
val f : (QueryImpl.QueryBuilder -> QueryImpl.QueryBuilder -> 'a)
val query : QueryImpl.QueryBuilder

Full name: FSharpComposableQuery.TopLevelValues.query
val student : schema.ServiceTypes.Student
custom operation: select ('Result)

Calls QueryBuilder.Select
property schema.ServiceTypes.Student.Age: Nullable<int>
property Nullable.Value: int
custom operation: contains ('T)

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

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
custom operation: count

Calls QueryBuilder.Count
val s : int
custom operation: sortBy ('Key)

Calls QueryBuilder.SortBy
custom operation: last

Calls QueryBuilder.Last
val number : int
custom operation: lastOrDefault

Calls QueryBuilder.LastOrDefault
val student2 : schema.ServiceTypes.Student

Full name: QueryExamples.student2
custom operation: where (bool)

Calls QueryBuilder.Where
property schema.ServiceTypes.Student.StudentID: int
custom operation: exactlyOne

Calls QueryBuilder.ExactlyOne
property schema.ServiceTypes.Student.Name: string
val student3 : schema.ServiceTypes.Student

Full name: QueryExamples.student3
custom operation: exactlyOneOrDefault

Calls QueryBuilder.ExactlyOneOrDefault
val student4 : schema.ServiceTypes.Student

Full name: QueryExamples.student4
custom operation: headOrDefault

Calls QueryBuilder.HeadOrDefault
type ServiceTypes =
  nested type Course
  nested type CourseSelection
  nested type LastStudent
  nested type MyDatabase
  nested type SimpleDataContextTypes
  nested type Student

Full name: QueryExamples.schema.ServiceTypes


<summary><para>The full API to the SQL connection.</para><para>To use the service via the full API, create an instance of one of the types 'MyDatabase'.</para></summary>
type Student =
  interface INotifyPropertyChanging
  interface INotifyPropertyChanged
  new : unit -> Student
  member Age : Nullable<int> with get, set
  member CourseSelection : EntitySet<CourseSelection> with get, set
  member Name : string with get, set
  event PropertyChanged : PropertyChangedEventHandler
  event PropertyChanging : PropertyChangingEventHandler
  member StudentID : int with get, set

Full name: QueryExamples.schema.ServiceTypes.Student
module Seq

from Microsoft.FSharp.Collections
val iter : action:('T -> unit) -> source:seq<'T> -> unit

Full name: Microsoft.FSharp.Collections.Seq.iter
val student5 : int

Full name: QueryExamples.student5
custom operation: minBy ('Value)

Calls QueryBuilder.MinBy
val student6 : int

Full name: QueryExamples.student6
custom operation: maxBy ('Value)

Calls QueryBuilder.MaxBy
custom operation: groupBy ('Key)

Calls QueryBuilder.GroupBy
val g : IGrouping<Nullable<int>,schema.ServiceTypes.Student>
property IGrouping.Key: Nullable<int>
(extension) Collections.Generic.IEnumerable.Count<'TSource>() : int
(extension) Collections.Generic.IEnumerable.Count<'TSource>(predicate: Func<'TSource,bool>) : int
val age : Nullable<int>
val count : int
member Nullable.Print : unit -> string
custom operation: sortByDescending ('Key)

Calls QueryBuilder.SortByDescending
custom operation: thenBy ('Key)

Calls QueryBuilder.ThenBy
custom operation: thenByDescending ('Key)

Calls QueryBuilder.ThenByDescending
custom operation: groupValBy ('Value) ('Key)

Calls QueryBuilder.GroupValBy
val g : IGrouping<Nullable<int>,string>
val group : IGrouping<Nullable<int>,string>
val name : string
custom operation: sumByNullable (Nullable<'Value>)

Calls QueryBuilder.SumByNullable
val sum : Nullable<int>
custom operation: minByNullable (Nullable<'Value>)

Calls QueryBuilder.MinByNullable
custom operation: maxByNullable (Nullable<'Value>)

Calls QueryBuilder.MaxByNullable
custom operation: averageBy ('Value)

Calls QueryBuilder.AverageBy
Multiple items
val float : value:'T -> float (requires member op_Explicit)

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

--------------------
type float = Double

Full name: Microsoft.FSharp.Core.float

--------------------
type float<'Measure> = float

Full name: Microsoft.FSharp.Core.float<_>
custom operation: averageByNullable (Nullable<'Value>)

Calls QueryBuilder.AverageByNullable
val float : value:Nullable<'T> -> Nullable<float> (requires member op_Explicit and default constructor and value type and 'T :> ValueType)

Full name: Microsoft.FSharp.Linq.Nullable.float
val avg : Nullable<float>
custom operation: find (bool)

Calls QueryBuilder.Find
custom operation: all (bool)

Calls QueryBuilder.All
type SqlMethods =
  static member DateDiffDay : startDate:DateTime * endDate:DateTime -> int + 3 overloads
  static member DateDiffHour : startDate:DateTime * endDate:DateTime -> int + 3 overloads
  static member DateDiffMicrosecond : startDate:DateTime * endDate:DateTime -> int + 3 overloads
  static member DateDiffMillisecond : startDate:DateTime * endDate:DateTime -> int + 3 overloads
  static member DateDiffMinute : startDate:DateTime * endDate:DateTime -> int + 3 overloads
  static member DateDiffMonth : startDate:DateTime * endDate:DateTime -> int + 3 overloads
  static member DateDiffNanosecond : startDate:DateTime * endDate:DateTime -> int + 3 overloads
  static member DateDiffSecond : startDate:DateTime * endDate:DateTime -> int + 3 overloads
  static member DateDiffYear : startDate:DateTime * endDate:DateTime -> int + 3 overloads
  static member Like : matchExpression:string * pattern:string -> bool + 1 overload

Full name: System.Data.Linq.SqlClient.SqlMethods
SqlMethods.Like(matchExpression: string, pattern: string) : bool
SqlMethods.Like(matchExpression: string, pattern: string, escapeCharacter: char) : bool
custom operation: head

Calls QueryBuilder.Head
val numbers : int
custom operation: nth (int)

Calls QueryBuilder.Nth
custom operation: skip (int)

Calls QueryBuilder.Skip
custom operation: skipWhile (bool)

Calls QueryBuilder.SkipWhile
custom operation: sumBy ('Value)

Calls QueryBuilder.SumBy
custom operation: take (int)

Calls QueryBuilder.Take
custom operation: takeWhile (bool)

Calls QueryBuilder.TakeWhile
custom operation: sortByNullable (Nullable<'Key>)

Calls QueryBuilder.SortByNullable
custom operation: sortByNullableDescending (Nullable<'Key>)

Calls QueryBuilder.SortByNullableDescending
custom operation: thenByNullable (Nullable<'Key>)

Calls QueryBuilder.ThenByNullable
custom operation: thenByNullableDescending (Nullable<'Key>)

Calls QueryBuilder.ThenByNullableDescending
module ExtraTopLevelOperators

from Microsoft.FSharp.Core
val query : QueryBuilder

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.query
val courseSelection : schema.ServiceTypes.CourseSelection
property schema.ServiceTypes.SimpleDataContextTypes.MyDatabase.CourseSelection: Data.Linq.Table<schema.ServiceTypes.CourseSelection>


Gets the 'CourseSelection' entities from the SQL connection. This property may be used as the source in a query expression.
custom operation: exists (bool)

Calls QueryBuilder.Exists
property schema.ServiceTypes.CourseSelection.StudentID: int
val n : schema.ServiceTypes.Student
val g : IGrouping<Nullable<int>,Nullable<int>>
val students : IGrouping<Nullable<int>,schema.ServiceTypes.Student>
Int32.ToString() : string
Int32.ToString(provider: IFormatProvider) : string
Int32.ToString(format: string) : string
Int32.ToString(format: string, provider: IFormatProvider) : string
val group : IGrouping<Nullable<int>,schema.ServiceTypes.Student>
val ageCount : int
val total : Nullable<int>
Nullable.GetValueOrDefault() : int
Nullable.GetValueOrDefault(defaultValue: int) : int
Nullable.ToString() : string
val myCount : int
val idList : int list

Full name: QueryExamples.idList
val idQuery : seq<int>

Full name: QueryExamples.idQuery
val id : int
(extension) Collections.Generic.IEnumerable.Contains<'TSource>(value: 'TSource) : bool
(extension) Collections.Generic.IEnumerable.Contains<'TSource>(value: 'TSource, comparer: Collections.Generic.IEqualityComparer<'TSource>) : bool
(extension) Collections.Generic.IEnumerable.Contains<'TSource>(value: 'TSource) : bool
String.Contains(value: string) : bool
(extension) Collections.Generic.IEnumerable.Contains<'TSource>(value: 'TSource, comparer: Collections.Generic.IEqualityComparer<'TSource>) : bool
val names : string []

Full name: QueryExamples.names
custom operation: join var in collection on (outerKey = innerKey). Note that parentheses are required after 'on'

Calls QueryBuilder.Join
val selection : schema.ServiceTypes.CourseSelection
property schema.ServiceTypes.CourseSelection.CourseID: int
custom operation: leftOuterJoin var in collection on (outerKey = innerKey) into group. Note that parentheses are required after 'on'

Calls QueryBuilder.LeftOuterJoin
val result : seq<schema.ServiceTypes.CourseSelection>
(extension) Collections.Generic.IEnumerable.DefaultIfEmpty<'TSource>() : Collections.Generic.IEnumerable<'TSource>
(extension) Collections.Generic.IEnumerable.DefaultIfEmpty<'TSource>(defaultValue: 'TSource) : Collections.Generic.IEnumerable<'TSource>
val selectionID : string
val studentID : string
val courseID : string
val sel : schema.ServiceTypes.CourseSelection
property schema.ServiceTypes.CourseSelection.ID: int
val e : schema.ServiceTypes.CourseSelection
custom operation: distinct

Calls QueryBuilder.Distinct
val query1 : IQueryable<string * Nullable<int>>

Full name: QueryExamples.Queries.query1
val query2 : IQueryable<string * Nullable<int>>

Full name: QueryExamples.Queries.query2
val n : schema.ServiceTypes.LastStudent
property schema.ServiceTypes.SimpleDataContextTypes.MyDatabase.LastStudent: Data.Linq.Table<schema.ServiceTypes.LastStudent>


Gets the 'LastStudent' entities from the SQL connection. This property may be used as the source in a query expression.
property schema.ServiceTypes.LastStudent.Name: string
property schema.ServiceTypes.LastStudent.Age: Nullable<int>
(extension) Collections.Generic.IEnumerable.Union<'TSource>(second: Collections.Generic.IEnumerable<'TSource>) : Collections.Generic.IEnumerable<'TSource>
(extension) IQueryable.Union<'TSource>(source2: Collections.Generic.IEnumerable<'TSource>) : IQueryable<'TSource>
(extension) Collections.Generic.IEnumerable.Union<'TSource>(second: Collections.Generic.IEnumerable<'TSource>, comparer: Collections.Generic.IEqualityComparer<'TSource>) : Collections.Generic.IEnumerable<'TSource>
(extension) IQueryable.Union<'TSource>(source2: Collections.Generic.IEnumerable<'TSource>, comparer: Collections.Generic.IEqualityComparer<'TSource>) : IQueryable<'TSource>
val query1 : IQueryable<string * Nullable<int>>

Full name: QueryExamples.Queries2.query1
val query2 : IQueryable<string * Nullable<int>>

Full name: QueryExamples.Queries2.query2
(extension) Collections.Generic.IEnumerable.Intersect<'TSource>(second: Collections.Generic.IEnumerable<'TSource>) : Collections.Generic.IEnumerable<'TSource>
(extension) IQueryable.Intersect<'TSource>(source2: Collections.Generic.IEnumerable<'TSource>) : IQueryable<'TSource>
(extension) Collections.Generic.IEnumerable.Intersect<'TSource>(second: Collections.Generic.IEnumerable<'TSource>, comparer: Collections.Generic.IEqualityComparer<'TSource>) : Collections.Generic.IEnumerable<'TSource>
(extension) IQueryable.Intersect<'TSource>(source2: Collections.Generic.IEnumerable<'TSource>, comparer: Collections.Generic.IEqualityComparer<'TSource>) : IQueryable<'TSource>
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<_>
val value : Nullable<int>
val course : schema.ServiceTypes.Course
property schema.ServiceTypes.SimpleDataContextTypes.MyDatabase.Course: Data.Linq.Table<schema.ServiceTypes.Course>


Gets the 'Course' entities from the SQL connection. This property may be used as the source in a query expression.
val iteri : action:(int -> 'T -> unit) -> source:seq<'T> -> unit

Full name: Microsoft.FSharp.Collections.Seq.iteri
val index : int
property schema.ServiceTypes.Course.CourseID: int
property schema.ServiceTypes.Course.CourseName: string
val studentName : string
val courseName : string
val g1 : seq<schema.ServiceTypes.CourseSelection>
val g2 : seq<schema.ServiceTypes.Course>
Fork me on GitHub