6 people like it.

OData Type Provider to StackOverflow

References and type definition to open StackOverflow API over OData

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
#r "System.Data.Services.Client"
#r "FSharp.Data.TypeProviders"

open Microsoft.FSharp.Data.TypeProviders

type stackOverflowData = 
    ODataService<"http://data.stackexchange.com/stackoverflow/atom">
let context = stackOverflowData.GetDataContext()

query { 
    for post in context.Posts do
    where (post.Tags.Contains "<f#>")
    sortByDescending post.CreationDate.Value
    take 10
    select post
}
|> Seq.map (fun post -> sprintf "%O %O %s" post.CreationDate post.AnswerCount post.Title)
|> Seq.toArray
namespace Microsoft
namespace Microsoft.FSharp
namespace Microsoft.FSharp.Data
namespace Microsoft.FSharp.Data.TypeProviders
type stackOverflowData

Full name: Script.stackOverflowData
type ODataService

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


<summary>Provides the types to access an OData service</summary><param name="ServiceUri">The Uri for the OData service</param><param name='LocalSchemaFile'>The local .csdl file for the service schema</param><param name='ForceUpdate'>Require that a direct connection to the service be available at design-time and force the refresh of the local schema file (default: true)</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='DataServiceCollection'>Generate collections derived from DataServiceCollection (default: false)</param>
val context : obj

Full name: Script.context
val query : Linq.QueryBuilder

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.query
val post : obj
custom operation: where (bool)

Calls Linq.QueryBuilder.Where
custom operation: sortByDescending ('Key)

Calls Linq.QueryBuilder.SortByDescending
custom operation: take (int)

Calls Linq.QueryBuilder.Take
custom operation: select ('Result)

Calls Linq.QueryBuilder.Select
module Seq

from Microsoft.FSharp.Collections
val map : mapping:('T -> 'U) -> source:seq<'T> -> seq<'U>

Full name: Microsoft.FSharp.Collections.Seq.map
val sprintf : format:Printf.StringFormat<'T> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.sprintf
val toArray : source:seq<'T> -> 'T []

Full name: Microsoft.FSharp.Collections.Seq.toArray

More information

Link:http://fssnip.net/f0
Posted:12 years ago
Author:Phillip Trelford
Tags: type providers , stackoverflow