我有这个功能,它将查询发送到我的Azure Mobile服务:
let pullTable<'a when 'a :> EntityDto> (logger: ILog) (table: Sync.IMobileServiceSyncTable<'a>) (tableQuery: IMobileServiceTableQuery<'a>) =
async {
match CrossConnectivity.Current.IsConnected with
| false -> ()
| true ->
try
do! table.PullAsync (Unchecked.defaultof<string>, tableQuery) |> Async.AwaitTask
with
| ex -> logger.Warning Tag (sprintf "Transient error: Connection failure") (Some ex)
}
从这种方法调用:
member this.GetVenuesAsync managerId =
async {
do! initialiseSyncContext mobileServiceClient
let table = mobileServiceClient.GetSyncTable<VenueDto>()
do! pullTable logger table (table.Where(fun v -> v.ManagerId = managerId))
let! results = table.ToEnumerableAsync() |> Async.AwaitTask
return results |> Array.ofSeq
}
不幸的是,此方法中的Where
子句完全无效:它会带回所有场地。
在端点停止服务器,table.PullAsync
生成的Odata查询中未添加任何过滤器。这看起来像是一个错误。
编辑1 :我也尝试过这种变化,但没有成功:
member this.GetVenuesAsync managerId =
async {
do! initialiseSyncContext mobileServiceClient
let table = mobileServiceClient.GetSyncTable<VenueDto>()
do! pullTable logger table (table.CreateQuery())
let! results = table.Where(fun v -> v.ManagerId = managerId).ToEnumerableAsync() |> Async.AwaitTask
return results |> Array.ofSeq
}
编辑2 :Bruce Chen的回答是部分解决方案,但它突出了另一个问题,我认为这是F#特有的。与
do! pullTable logger table (table.CreateQuery().Where(fun v -> v.ManagerId = managerId))
端点确实拾取了过滤器,但遗憾的是,过滤器格式错误。在我TableController
的终端
[EnableQuery] public IHttpActionResult Get() => Ok(Query());
RequestUrl
的查询字符串包含$filter=(managerId%20eq%202L)
。此L后缀是一个问题:managerId
被定义为int
,而不是long
。但odata端点将其解释为long
。我不知道是否有一种简单的方法可以解决这个问题。
答案 0 :(得分:1)
根据我的理解,您可以尝试更改代码,如下所示,通过ManagerId
方法从特定PullAsync
的远程Venue表中提取记录。
do! pullTable logger table (table.CreateQuery())
//To
do! pullTable logger table (table.CreateQuery().Where(fun v -> v.ManagerId = managerId))
以下是使用C#编写的过滤器提取记录的tutorial,您可以参考它并查看代码。