2013-01-12 35 views
6

Tôi đang cố sử dụng nhà cung cấp loại ODataService với Netflix. Điều này hoạt động tốt:Không có thuộc tính 'HasValue' nào tồn tại đối với không có giá trị int cho Nhà cung cấp Loại ODataService

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 

nhưng trả về tất cả các tập của chương trình truyền hình Godzilla, không có ngày phát hành (boo). Vì vậy, tôi cập nhật truy vấn của tôi để:

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 

Và tôi phải đối mặt với các lỗi sau:

<?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 không tồn tại cho ints nullable? Kể từ khi?

Trả lời

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ôi phải chuyển đổi các lựa chọn cho 'chọn (t.Name, t.ReleaseYear.Value)' nhưng hoàn hảo, cảm ơn. – rachel