Use the resx type provider

Category:
TypeProviders.Others
Description: Use the resx type provider. The string1 and string2 are defined in the resource file.
Code:
[<Generate>]
type T = Microsoft.FSharp.Data.TypeProviders.ResxFile< @"Support_Resource.resx" >

let typeResxProviderTest() =
let string1 = T.Support_Resource.String1
let string2 = T.Support_Resource.String2
printfn "string1 from resource is %s" string1
printfn "string2 from resource is %s" string2


Execution Result:
string1 from resource is aa
string2 from resource is MyString2

DBML Provider

Category:
TypeProviders.Others
Description: Use DBML provider for FSharpSample database. You can download the SQL server 2008 Express version for free. Please refer to CreateFSharpSampleDatabase.sql or run Setup project to configure your database.
Code:
[<Generate>]

type T1 = Microsoft.FSharp.Data.TypeProviders.DbmlFile< @".\Support.DataClasses.dbml" >
let typeDBMLProvider() =
let db = new T1.DataClasses1DataContext("Data Source=localhost;Initial Catalog=FSharpSample;User ID=sa;Password=FSharpSample1234")
let q = query {
for n in db.Students do
select n.Name }
q |> Seq.iter (fun n -> printfn "student name = %s" n)


Execution Result:
student name = Lisa
student name = Brent
student name = Anita
student name = Ken
student name = Cathy
student name = Tom
student name = Zeoy
student name = Mark
student name = John

DBML Provider - Console.Out as output

Category:
TypeProviders.Others
Description: Use Console.Out to log the underlying query. You can download the SQL server 2008 Express version for free. Please refer to CreateFSharpSampleDatabase.sql or run Setup project to configure your database.
Code:
[<Generate>]

type T1 = Microsoft.FSharp.Data.TypeProviders.DbmlFile< @".\Support.DataClasses.dbml" >
let typeDBMLProvider2() =
let db = new T1.DataClasses1DataContext("Data Source=localhost;Initial Catalog=FSharpSample;User ID=sa;Password=FSharpSample1234")
db.Log <- Console.Out
let q = query {
for n in db.Students do
select n.Name }
q |> Seq.iter (fun n -> printfn "student name = %s" n)


Execution Result:
SELECT [t0].[Name]
FROM [dbo].[Student] AS [t0]
-- Context: SqlProvider(Sql2008) Model: AttributedMetaModel Build: 4.0.30319.17281

student name = Lisa
student name = Brent
student name = Anita
student name = Ken
student name = Cathy
student name = Tom
student name = Zeoy
student name = Mark
student name = John

EDMX Provider

Category:
TypeProviders.Others
Description: define a EDMX type provider on the local SQL server database. You can download the SQL server 2008 Express version for free. Please refer to CreateFSharpSampleDatabase.sql or run Setup project to configure your database.
Code:
[<Generate>]

type T2 = Microsoft.FSharp.Data.TypeProviders.EdmxFile< @".\Support.Model.edmx" >

let typeEdmxProvider() =
let db = new T2.FSharpSampleModel.Entities("metadata=res://*/Support.Model.csdl|res://*/Support.Model.ssdl|res://*/Support.Model.msl;provider=System.Data.SqlClient;provider connection string=\"Data Source=localhost;Initial Catalog=FSharpSample;User ID=sa;Password=FSharpSample1234\"")
let q = query {
for n in db.Students do
select n.Name }
q |> Seq.iter (fun n -> printfn "%A" n)


Execution Result:
"Lisa"
"Brent"
"Anita"
"Ken"
"Cathy"
"Tom"
"Zeoy"
"Mark"
"John"

WsdlService - w3cschools temperature conversion

Category:
TypeProviders.Others
Description: define a WSDL type provider and do temperature conversion from w3cschools web site.
Code:
[<Generate>]

type T3 = Microsoft.FSharp.Data.TypeProviders.WsdlService< "http://www.w3schools.com/webservices/tempconvert.asmx?WSDL" >

let WsdlSample1() =
let db = T3.GetHttpTempConvertSoapClient()
let a = db.CelsiusToFahrenheit("0")
printfn "%s" a


Execution Result:
32

WsdlService - Bing Map rounting service

Category:
TypeProviders.Others
Description: Using Bing Map API routing service to calculate the driving distance between two addresses. For more information, please goto http://www.microsoft.com/maps/developers/mapapps.aspx. Please make sure you setup the correct credential.
Code:
[<Generate>]

type G = Microsoft.FSharp.Data.TypeProviders.WsdlService//dev.virtualearth.net/webservices/v1/geocodeservice/geocodeservice.svc?wsdl">
[<Generate>]

type R = Microsoft.FSharp.Data.TypeProviders.WsdlService//dev.virtualearth.net/webservices/v1/routeservice/routeservice.svc?wsdl">

type GeoCommon = G.ServiceTypes.dev.virtualearth.net.webservices.v1.common
type Geocode = G.ServiceTypes.dev.virtualearth.net.webservices.v1.geocode
type RouteCommon = R.ServiceTypes.dev.virtualearth.net.webservices.v1.common
type Route = R.ServiceTypes.dev.virtualearth.net.webservices.v1.route

let WsdlBingMap() =
let geoClient = G.GetHttpGeocodeServiceClient()
let geoReq = new Geocode.GeocodeRequest()
//To sign up for a Bing service developer account @ https://www.bingmapsportal.com/application/index/1034110
geoReq.Credentials <- new GeoCommon.Credentials(ApplicationId = Utils.BING_APP_ID)

geoReq.Query <- "One Microsoft Way, Redmond, WA 98052"
let response = geoClient.Geocode(geoReq)
let work = response.Results.[0]

geoReq.Query <- "400 Broad St Seattle, WA 98109"
let response2 = geoClient.Geocode(geoReq)
let home = response2.Results.[0]

let startPoint = new Route.Waypoint()
startPoint.Location <- new RouteCommon.Location(Latitude = work.Locations.[0].Latitude,
Longitude = work.Locations.[0].Longitude)
let endPoint = new Route.Waypoint()
endPoint.Location <- new RouteCommon.Location(Latitude = home.Locations.[0].Latitude,
Longitude = home.Locations.[0].Longitude)

let routReq1 = new Route.RouteRequest(Waypoints = [|startPoint; endPoint|])
routReq1.Credentials <- new RouteCommon.Credentials(ApplicationId = Utils.BING_APP_ID)

printfn "Driving Distance = %A (miles)" (R.GetHttpRouteServiceClient().CalculateRoute(routReq1).Result.Summary.Distance)

// sample output
// Driving Distance = 22.998 (miles)
Execution Result:
Driving Distance = 22.998 (miles)

Last edited Sep 13, 2011 at 12:56 AM by ttliu2000, version 1

Comments

No comments yet.