Use the OData service to access Azure data market data source

Category:
TypeProviders.ODataService
Description: Use the OData service to access Azure data market data source. For this sample, we access the UK travel information data from Azure data market. You need Azure data maket user name and credential to access this free data.
Code:
[<Generate>]
type TOData = Microsoft.FSharp.Data.TypeProviders.ODataService//api.datamarket.azure.com/Uk.Gov/TravelAdvisoryService/" >

let typeProviderODataSample() =
let travelInfo = TOData.GetDataContext()
//To sign up for a Windows Azure Marketplace account @ https://datamarket.azure.com/account/info
do travelInfo.Credentials <- new NetworkCredential (Utils.ADM_USER_ID, Utils.ADM_ACCOUNT_ID)

query {
for n in travelInfo.BritishEmbassiesAndHighCommissions do
select n
take 2
}|> Seq.iter (fun n -> printfn "%s\n" n.Address)

// sample output
// 1A Brisbane Street
// Hobart
// Tasmania
// 7000
// ,Hobart
//
// 444-446 Pulteney Street
// Adelaide
// SA 5000
// ,Adelaide

Execution Result:
1A Brisbane Street
Hobart
Tasmania
7000
,Hobart

444-446 Pulteney Street
Adelaide
SA 5000
,Adelaide


Northwind public OData Service

Category:
TypeProviders.ODataService
Description: Consume Northwind public OData Service published by http://www.odata.org
Code:
[<Generate>]

type Northwind = Microsoft.FSharp.Data.TypeProviders.ODataService<"http://services.odata.org/Northwind/Northwind.svc/">

let typeProviderODataSample1() =
let db = Northwind.GetDataContext()

query {
for n in db.Customers do
select n
take 2
}|> Seq.iter (fun n -> printfn "%s\n" n.ContactName)

// sample output
// Maria Anders
// Ana Trujillo


Execution Result:
Maria Anders

Ana Trujillo


Last edited Sep 12, 2011 at 11:55 PM by ttliu2000, version 1

Comments

No comments yet.