2013-01-12 23 views
6

我試圖在Netflix中使用ODataService類型提供程序。這工作正常:對於ODataService類型提供程序,不存在用於可爲空的int的屬性「HasValue」

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 

但返回哥斯拉電視節目的所有情節,沒有發佈年份日期(噓)。所以,我更新我的查詢:

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 

而且我面臨着以下錯誤:

<?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> 

呃,的HasValue不存在爲空的整型?從何時起?

回答

6
#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 
+0

我不得不選擇切換到'選擇(t.Name,t.ReleaseYear.Value)' 但完美的,謝謝。 – rachel

相關問題