Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No property 'HasValue' exists for nullable int for ODataService Type Provider

I'm trying to use the ODataService type provider with Netflix. This works fine:

type internal NetflixData = ODataService<"http://odata.netflix.com/Catalog/">
let internal NetflixContext = NetflixData.GetDataContext()

let godzillamovies = query { for t in NetflixContext.Titles do 
                             where (t.Name.Contains "Godzilla")
                             select (t.Name, t.ReleaseYear)
                           } |> Seq.toList

but returns all the episodes of the Godzilla TV show, with no release year dates (boo). So, I update my query to:

let godzillamovies = query { for t in NetflixContext.Titles do 
                             where (t.Name.Contains "Godzilla" && t.ReleaseYear.HasValue)
                             select (t.Name, t.ReleaseYear.Value)
                           } |> Seq.toList

And I'm confronted with the following error:

<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>
<error xmlns=\"http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\">
  <code></code>
  <message xml:lang=\"en-US\">No property 'HasValue' exists in type 'System.Nullable`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' at position 45.</message>
</error>

Uh, HasValue doesn't exist for nullable ints? Since.. when?

like image 909
rachel Avatar asked Jan 12 '13 20:01

rachel


1 Answers

#r "FSharp.Data.TypeProviders"
#r "System.Data.Services.Client"

open Microsoft.FSharp.Data.TypeProviders
open Microsoft.FSharp.Linq.NullableOperators

type internal NetflixData = ODataService<"http://odata.netflix.com/Catalog/">
let internal NetflixContext = NetflixData.GetDataContext()

NetflixContext.DataContext.SendingRequest.Add(fun e -> printfn "%A" e.Request.RequestUri)

// http://odata.netflix.com/Catalog/Titles()?$filter=substringof('Godzilla',Name) and (ReleaseYear ne null)&$select=Name,ReleaseYear
let godzillamovies = query { for t in NetflixContext.Titles do 
                             where (t.Name.Contains "Godzilla")
                             where (t.ReleaseYear ?<>? System.Nullable())
                             select (t.Name, t.ReleaseYear)
                           } |> Seq.toList
like image 106
desco Avatar answered Nov 02 '22 20:11

desco