Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EBay OData Type Provider in F# and getting no results with LINQ

Can anyone help me understand why the piece of code below returns no results from the query yet the second sample does (though woe betide me if I try to use criteria on the second one!)

 type EbayData = 
    ODataService<"http://ebayodata.cloudapp.net">

let Ebay = EbayData.GetDataContext()

let Favourites title number = query{
    for deal in Ebay.Deals do
    where (deal.Title.Contains(title))
    take number
    }


let Esearch title number =  [for item in Favourites title number do 
                                  yield item]

The working version:

type Catalog = ODataService< "http://ebayodata.cloudapp.net/" >

let ebay = Catalog.GetDataContext()

let trial =
            [ for item in ebay.Deals do
               yield item]

I can't seem to output the first to any kind of list, no matter what do with |> etc. The second sample doesn't seem to bring back many resuls to do a text query on. However, my real issue is I can't seem to get anything out of the LINQ in F# version.

The output is used in a WPF application where I use VB to talk to the list. I have populated a non discriminated list of 10 items with it, so that end does work. This is the VB code.

 For Each Deal In trial.Where(Function(p) p.Title.Contains(title.Text))
                DealResults.Items.Add(buildStackPanel(Deal))
            Next

The spacing for the F Sharp on this post doesn't seem to work when I hit Ctrl-K so if anyone can tell me what I'm doing wrong - I guess that's a second question!

like image 501
Richard Griffiths Avatar asked Dec 04 '12 06:12

Richard Griffiths


1 Answers

I don't know why this is not working for you. I knocked out the following and it seems to work:

open Microsoft.FSharp.Data
type Catalog = TypeProviders.ODataService< "http://ebayodata.cloudapp.net/" >

let ebay = Catalog.GetDataContext()

let trial =
            [ for item in ebay.Deals do
               yield item]
let trial2 = query {
                for deal in ebay.Deals do
                where (deal.Title.Contains "a")
                take 2
             }
let ESearch title number =
             query {
                for deal in ebay.Deals do
                where (deal.Title.Contains title)
                take number
             }

[<EntryPoint>]
let main argv = 
    trial |> Seq.take 2 |> Seq.iter (fun d -> printfn "%s" d.Title)
    trial2 |> Seq.iter (fun d -> printfn "%s" d.Title)
    ESearch "a" 2 |> Seq.iter (fun d -> printfn "%s" d.Title)

    0

Maybe you tried searching for stuff that doesn't exist? At the moment there are only 6 deals, so this is not unlikely.

Querying Items

Read about the eBay OData service here: http://ebayodata.cloudapp.net/docs It has special needs when querying for Items:

(search parameter or $filter with Seller, PrimaryCategoryId or SecondaryCategoryId is required)

So to query Items, you'll need to provide at least a search phrase. Your where statement doesn't get translated to a search parameter in the final url. To add custom parameters in this Type Provider, you do .AddQueryOption.

let ItemSearch title number =
             query {
                for item in ebay.Items
                             .AddQueryOption("search", title) do
                take number
             }
// use
ItemSearch "wario" 2 |> Seq.iter (fun d -> printfn "%s" d.Title)
like image 85
Robert Jeppesen Avatar answered Sep 21 '22 14:09

Robert Jeppesen