/// <summary> /// Counts all the items returned from the query /// </summary> /// <param name="store">An instance of <see cref="IMobileServiceLocalStore"/></param> /// <param name="query">An instance of <see cref="MobileServiceTableQueryDescription"/></param> /// <returns>Task that will complete with count of items.</returns> public static async Task <long> CountAsync(this IMobileServiceLocalStore store, MobileServiceTableQueryDescription query) { query.Top = 0; query.IncludeTotalCount = true; QueryResult result = await store.QueryAsync(query); return(result.TotalCount); }
public static async Task <OperationQueue> LoadAsync(IMobileServiceLocalStore store) { var opQueue = new OperationQueue(store); var query = CreateQuery(); // to know how many pending operations are there query.IncludeTotalCount = true; // to get the max sequence id, order by sequence desc query.Ordering.Add(new OrderByNode(new MemberAccessNode(null, "sequence"), OrderByDirection.Descending)); // we just need the highest value, not all the operations query.Top = 1; QueryResult result = await store.QueryAsync(query); opQueue.pendingOperations = result.TotalCount; opQueue.sequenceId = result.Values == null ? 0 : result.Values.Select(v => v.Value <long>("sequence")).FirstOrDefault(); return(opQueue); }
/// <summary> /// Executes the query on local store and returns the first or default item from parsed result /// </summary> /// <param name="store">An instance of <see cref="IMobileServiceLocalStore"/></param> /// <param name="query">An instance of <see cref="MobileServiceTableQueryDescription"/></param> /// <returns>Task that will complete with the first or default item from parsed result of the query.</returns> public static async Task <JObject> FirstOrDefault(this IMobileServiceLocalStore store, MobileServiceTableQueryDescription query) { QueryResult result = await store.QueryAsync(query); return(result.Values.FirstOrDefault() as JObject); }
public static async Task<OperationQueue> LoadAsync(IMobileServiceLocalStore store) { var opQueue = new OperationQueue(store); var query = CreateQuery(); // to know how many pending operations are there query.IncludeTotalCount = true; // to get the max sequence id, order by sequence desc query.Ordering.Add(new OrderByNode(new MemberAccessNode(null, "sequence"), OrderByDirection.Descending)); // we just need the highest value, not all the operations query.Top = 1; QueryResult result = await store.QueryAsync(query); opQueue.pendingOperations = result.TotalCount; opQueue.sequenceId = result.Values == null ? 0 : result.Values.Select(v => v.Value<long>("sequence")).FirstOrDefault(); return opQueue; }