F Sharp, LINQ and SQL

Today I found another way to talk to a database. This brings the count up to 4 if you include EF, Custom connectors, Datasets and now, F Sharp Type providers. F# is a great language for rules,specialist tools and data exploration.

Type providers, a feature introduced in F# 3.0, allows for strongly typed access to external data sources without having to be aware of the schema ahead of time.

A great starting book on this intriguing language. F# Survival Guide

Simple example:

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

type dbschema = SqlDataConnection<"Data Source=Katrina\SQLExpress;Initial Catalog=RCPD;Integrated Security=SSPI;">
let db = dbschema.GetDataContext()

db.DataContext.Log |> System.Console.Out

let query1 =
        query {
               for row in db.TableName do
               select row

query1 |> Seq.iter (fun row -> printfn "%A %A" row.SomeId row.SomeName)