我有以下代码,目的是列出Freebase上列出的证券交易所网站:
#if INTERACTIVE
#r @"C:\Users\kit\Documents\Visual Studio 11\Projects\Demo\packages\FSharpx.TypeProviders.1.7.4\lib\40\FSharpx.TypeProviders.dll"
#r @"C:\Users\kit\Documents\Visual Studio 11\Projects\Demo\packages\FSharpx.TypeProviders.Freebase.1.7.4\lib\40\FSharpx.TypeProviders.Freebase.dll"
#r @"C:\Users\kit\Documents\Visual Studio 11\Projects\Demo\packages\FSharpx.TypeProviders.Freebase.1.7.4\lib\40\FSharpx.TypeProviders.Freebase.DesignTime.dll"
#endif
let GetExchanges() =
let dc = FreebaseData.GetDataContext()
dc.DataContext.SendingRequest.Add(fun e -> printfn "url: %s" e.RequestUri.AbsoluteUri)
dc.``Products and Services``.Business.``Stock exchanges``
|> Seq.truncate 10
|> Seq.iter (fun exchange -> printfn "Exchange: %s" exchange.Name
exchange.``Official website``
|> Seq.iter (fun site -> printfn "%s" site.Name))
没有最后两行(即只列出Exchange名称),代码工作正常。使用这些行我得到400(错误请求)。
该行生成的URL为:
...如果我浏览到我从Freebase获得这个:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "badRequest",
"message": "Can't reverse /common/topic/official_website as it expects /type/uri, not an object"
}
],
"code": 400,
"message": "Can't reverse /common/topic/official_website as it expects /type/uri, not an object"
}
}
我使用正确的方法访问链接的实体吗?如果是这样,这是类型提供程序中的错误吗?我在访问其他链接实体时遇到类似的错误。
答案 0 :(得分:4)
此类型提供程序中的错误已修复:https://github.com/fsharp/FSharp.Data/issues/68
答案 1 :(得分:4)
就像错误所说的那样,你不能反转属于原始值属性的属性。您需要将查询内部翻出来,使其看起来像:
[{
"/type/object/id": "/en/amex",
"/common/topic/official_website": [{
"value": null,
"optional": true
}]
}]
库必须具有一些原始值的知识,所以也许这对于包含/ type / text,/ type / rawstring等的任何列表添加/ type / uri都很简单。