使用Azure Get Service传递参数 [英] Parameter Passing with Azure Get Service

查看:66
本文介绍了使用Azure Get Service传递参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定如何执行此操作,这是Azure的新增功能,我正在使用Azure的公共接口IMobileServiceSyncTable:IMobileServiceSyncTable",并从一个特定的表中获取记录,我在以下一种方法中使用该方法: 查询= table.CreateQuery(); await table.PullAsync(typeof(T).Name,query);"

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);"

这使我获得了该特定表的所有记录,现在我希望传递一个参数,即USERID,因此我仅获得属于该用户的那些记录.

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.

预先感谢.

推荐答案

只需在查询中添加Where子句,就像在常规LINQ中一样:

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.

有关更多信息,请参见 Azure移动应用程序中的脱机数据同步.

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

最后,在客户端上进行用户ID过滤通常不是一个好主意,因为它的安全性较低.任何人都可以发出HTTP调用来检索不属于它们的值.更好的方法是在服务器上调整查询.

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 a Node.js backend: 30 Days of Zumo.v2 (Azure Mobile Apps): Day 6 – Personal Tables
  • For .NET: Sample of Where clause in TableController.

这篇关于使用Azure Get Service传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆