ClubberLang
ClubberLang

Reputation: 1898

Cosmos DB - Unable to retreive from Xamarin

I have a Cosmos DB database and try to retrieve some documents with Xamarin, but I failed !

As expected, I used the following package : Microsoft.Azure.DocumentDB.Core 1.9.1 https://www.nuget.org/packages/Microsoft.Azure.DocumentDB.Core

I have tried to follow the MS Documentation here : https://learn.microsoft.com/en-us/xamarin/xamarin-forms/data-cloud/cosmosdb/consuming

The problem is that it uses some functions that doesn't exists! By example :

var query = client.CreateDocumentQuery<TodoItem>(collectionLink).AsDocumentQuery();
while (query.HasMoreResults) Items.AddRange(await query.ExecuteNextAsync<TodoItem>());

The AsDocumentQuery, HasMoreResults, ExecuteNextAsync are not there !!

I have try this :

        var query = _client.CreateDocumentQuery<Item>(collectionUri);
        var enumerator = query.GetEnumerator();

        while (enumerator.MoveNext())
        {
            var item = enumerator.Current;
        }

But my "Item" are empty, not initialized at all !

Any idea ?

Thanks

Upvotes: 0

Views: 60

Answers (1)

Rafat Sarosh
Rafat Sarosh

Reputation: 945

Couple of things: add the line

using Microsoft.Azure.Documents.Linq;

Second, make sure your collection is not empty. Go to portal and add a document and then try your code.

Code should work with 1.9.1 but feel free to upgrade.

Upvotes: 1

Related Questions