0

I want to get value of a variable(InputAssetId) stored in a document as a string.Wrote the query.It works fine in the QueryExplorer.

 this.client = new DocumentClient(new Uri(EndpointUri), PrimaryKey);
 IQueryable<asset> id = this.client.CreateDocumentQuery<asset>(
               UriFactory.CreateDocumentCollectionUri(DatabaseName,CollectionName),
               "SELECT c.InputAssetId FROM c WHERE c.BlobNameDb='BigBuckBunny.mp4' ");
 Console.WriteLine( id.string());

Instead of a value stored in the variable,what i got in the console is given below

{"query":"SELECT c.InputAssetId FROM c WHERE c.BlobNameDb='BigBuckBunny.mp4' "}

Can anyone please give me a solution?

5
  • What's the problem? That looks like a valid SQL query to me. Commented Sep 7, 2016 at 13:16
  • What is asset? And by the way, shouldn't you get a IQueryable<string> if you select the id only? Commented Sep 7, 2016 at 14:42
  • @ShannonHolsinger I want to print the value of "InputAssetId" in the console.Instead what i got in the console is given in the question.This is the problem. Commented Sep 7, 2016 at 15:19
  • @C.Champagne Tried using IQueryable<string>. Still getting the same output. Commented Sep 7, 2016 at 15:21
  • Sorry - been up too long. Commented Sep 7, 2016 at 15:26

2 Answers 2

1

The issue is that you aren't actually ever executing the query you've created. The correct code would be something along those lines:

this.client = new DocumentClient(new Uri(EndpointUri), PrimaryKey);
var query = this.client.CreateDocumentQuery<asset>(
         ... your LiNQ or SQL query...
    .AsDocumentQuery();

var result = await query.ExecuteNextAsync<string>();
Console.WriteLine(result.ToList().FirstOrDefault());

You may want to use TOP 1 in the query (and not FeedOptions.MaxItemCount = 1, as the latter is badly named - it actually means how many items per feed request are returned at the most. Using low MaxItemCount can lead to great number of useless queries).

Sign up to request clarification or add additional context in comments.

Comments

0

Well I still don't know all the API that well but I would use Linq with C#. `.

You should write it more or less that way :

FeedOptions queryOptions = new FeedOptions { MaxItemCount = 1 };

IQueryable<Asset> assetQuery = client.CreateDocumentQuery<Asset>(UriFactory.CreateDocumentCollectionUri(DatabaseName, CollectionName),

queryOptions) .Where(o => o.BlobNameDb == "BigBuckBunny.mp4");

string id = assetQuery.First().InputAssetId ;

From what I can read in the documentation you want to use SQL query, you have to pass it as a SqlQuerySpec so your code could become (haven't tested the solution though):

IQueryable<string> assetQuery = client.CreateDocumentQuery<Asset>(
          UriFactory.CreateDocumentCollectionUri(DatabaseName, CollectionName), 
          new SqlQuerySpec("SELECT c.InputAssetId FROM c WHERE c.BlobNameDb='BigBuckBunny.mp4'"),
          queryOptions)
string id = assetQuery.First();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.