Parameter Passing with Azure Get Service

时光毁灭记忆、已成空白 提交于 2019-12-12 01:43:09

问题


I am not sure how to do this, new with azure, i am using "public interface IMobileServiceSyncTable : IMobileServiceSyncTable" of Azure and to fetch the records from one particular table, i am using below in a method: "query = table.CreateQuery(); await table.PullAsync(typeof(T).Name, query);"

this gets me all the records of this particular table, now i wish to pass a parameter viz USERID, so i get only those records that belongs to this user.

Can anyone help me with an example for this?

Also it would be great if there is an example to fetch data with multiple parameters.

Thanks in Advance.


回答1:


Just add a Where clause to the query, as in regular LINQ:

await todoTable.PullAsync("todoItems" + userid, syncTable.Where(u => u.UserId == userid));

Also, if you are using multiple queries against the same table name, make sure you use a unique query name (the first parameter) for them. This is because incremental sync uses this query name in order to store the last updated value for the previous sync operation.

For more information, see Offline Data Sync in Azure Mobile Apps.

Finally, it's usually not a good idea to do user ID filtering on the client, because it is less secure. Anyone could issue an HTTP call to retrieve values that do not belong to them. A better way is to adjust the query on the server.

For examples of this, see:

  • For a Node.js backend: 30 Days of Zumo.v2 (Azure Mobile Apps): Day 6 – Personal Tables
  • For .NET: Sample of Where clause in TableController.


来源:https://stackoverflow.com/questions/38367610/parameter-passing-with-azure-get-service

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