Created
April 18, 2012 21:17
-
-
Save Thorium/2416622 to your computer and use it in GitHub Desktop.
F# 3.0 - EntityFramework Type Provider usage with Northwind DB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//A small sample how to use F# 3.0 Entity Framework (EF) Type Provider. Visual Studio 11 Beta (and Northwind sample database) needed. | |
(* | |
#r "System.Data.Entity.dll" | |
#r "FSharp.Data.TypeProviders.dll" | |
*) | |
open System | |
open Microsoft.FSharp.Data.TypeProviders | |
module Queries = | |
[<Literal>] | |
let connectionstring = "Server=localhost;Initial Catalog=Northwind;Integrated Security=SSPI;MultipleActiveResultSets=true" | |
//<interactive at once> | |
type private EntityConnection = SqlEntityConnection<ConnectionString=connectionstring, Pluralize = true> | |
let fetchCustomers = | |
let context = EntityConnection.GetDataContext() | |
query { for customer in context.Customers do | |
where (customer.Country = "Finland") | |
select (customer.ContactName, customer.CompanyName) } | |
//</interactive at once> | |
let show = fetchCustomers |> Seq.iter (fun i -> Console.WriteLine("Customer: " + fst i + ", Company: " + snd i)) | |
(* Output: | |
Customer: Pirkko Koskitalo, Company: Wartian Herkku | |
Customer: Matti Karttunen, Company: Wilman Kala | |
val show : unit = () | |
*) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment