Azure Mobile Service query doesn't return all the rows
Asked Answered
D

3

6

I have a table called NameTable in my Azure Mobile Service. When I make the below mentioned calls in my client app (WP8 app using the Mobile Services SDK):

var myTable = GetZumoService().GetTable<NameTable>();
var myList = await myTable.Where(nameInfo => nameInfo.IsTaken == false).ToListAsync();

myList always contains only 50 items although I know that there are more than 400 rows in the tables that match the query condition.

What am I doing wrong?

Definiendum answered 30/12, 2012 at 5:7 Comment(0)
C
16

By default the service will only return a certain number of rows in each Read operation (50, as you noticed). Since there are quotas for the number of returned bytes in Azure services when they're free (and costs for paid ones), the mobile service has this default.

You can ask for more rows, using the Take operation. There is, however, a limit on the number of rows which you can ask at any given time (which is 1000). The idea is that you shouldn't ask for all data in a table - it can potentially be a lot - and ask for rows as you need them using the Skip and Take operations.

var myTable = GetZumoService().GetTable<NameTable>();
var myList = await myTable.Take(500)
                          .Where(nameInfo => nameInfo.IsTaken == false)
                          .ToListAsync();
Coniah answered 30/12, 2012 at 16:35 Comment(4)
OK thanks. Do you also know if there is a way to insert, update or delete multiple records in one API call?Definiendum
Btw, how do I find out what the limit is on number of rows that I can ask for? Also can you share some code which shows how to page through all the rows in a table?Definiendum
Edited to add the maximum number of rows to request. You can find more about adding paging in the tutorial at windowsazure.com/en-us/develop/mobile/tutorials/….Coniah
Regarding insert / update / delete multiple records, yes, it's possible, although you'll need to do that via server-side scripts.Coniah
I
9

I found that this was not enough. You need to decorate your Azure Mobile Service controller method with the [EnableQuery] attribute as follows:

[EnableQuery(PageSize=1000)]
public IQueryable<MyDataTable> GetOneThousandRecords()
{
    return Query()
}
Irresponsible answered 23/1, 2015 at 19:22 Comment(0)
R
0

Because of the server sides behaviour I had to change my script in the easy tables like following: MSDN Forum

Use the App Service Editor, edit the tableName.js file (in the tables directory, replacing tableName with your tablename), then set: table.maxTop = 1000 You can also set table.pageSize = 1000 to set the default page size.

Setting table.pageSize = 1000; worked for me.

Reflex answered 17/5, 2018 at 9:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.