我正在尝试将Netataix与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
但返回哥斯拉电视节目的所有剧集,没有发行年份日期(嘘声)。所以,我将查询更新为:
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对于可以为空的整数是不存在的?既然......什么时候?
答案 0 :(得分: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