gpt4 book ai didi

f# - ODataService 类型提供程序的可为空整数不存在属性 'HasValue'

转载 作者:行者123 更新时间:2023-12-04 15:01:11 25 4
gpt4 key购买 nike

我正在尝试将 ODataService 类型提供程序与 Netflix 一起使用。这工作正常:

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 吗?从何时起?

最佳答案

#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

关于f# - ODataService 类型提供程序的可为空整数不存在属性 'HasValue',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14297860/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com