Search code examples
azurexamarin.formsazure-mobile-services

Parameter Passing with Azure Get Service


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.


Solution

  • 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: