Azure Offline Sync - How to use “Contains”

佐手、 提交于 2019-12-08 11:29:45

问题


I have an Azure Table and I want to sync it offline on my mobile device, Everything works fine if I pass single where clause such as following

var query = todoTable.CreateQuery().Where(c => c.Id == "some id here");
await todoTable.PullAsync(null, query);

But I have a List which contains multiple IDs such as

List<string> IDS = new List<string>();
IDS.Add("Some ID 1");
IDS.Add("Some ID 2");

and I am trying to pass that in my query as following to only get items with specific Ids

var query = todoTable.CreateQuery().Where(c => IDS.Contains(c.Id));
await todoTable.PullAsync(null, query);

But this seems not to be working,

Is there a way to do this?


回答1:


var query = todoTable.CreateQuery().Where(c => IDS.Contains(c.Id));

await todoTable.PullAsync(null, query);

Per my understanding, your pull operation would execute the following request against your mobile backend:

GET https://{your-app-name}.azurewebsites.net/tables/{your-table-name}?$filter=((id eq 'Some ID 1') or (id eq 'Some ID 2'))

TEST:

Based on my testing, the above pull operation could work as expected on my side. I recommend you use fiddler to capture the network trace when invoking the pull operation to make sure that you could retrieve the records as expected. Moreover, you could follow Debugging the Offline Cache.

UPDATE:

I checked this issue on my C# mobile app backend to narrow down this issue. I set config.IncludeErrorDetailPolicy to IncludeErrorDetailPolicy.Always under Startup.MobileApp.cs for retrieving detailed error messages. And I found that I could encounter the following error:

I assumed that we may hit the ODataValidationSettings.MaxNodeCount which is used to determine the maximum of the nodes inside the $filter syntax tree. Then, I decorated my action as follows to increase the MaxNodeCount limitation, and found that the query could work as expected.

[EnableQuery(MaxNodeCount =1000)]
public IQueryable<ToDoItem> GetAllTodoItems()


来源:https://stackoverflow.com/questions/48972334/azure-offline-sync-how-to-use-contains

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!