Home > Net >  Trying to get object from CosmosDb via MVC app via client.CreateDocumentQuery
Trying to get object from CosmosDb via MVC app via client.CreateDocumentQuery

Time:02-23

First attempt at accessing Cosmos db.

All this is in a DAL project layer of the solution (n-tier). EndPointURI and PrimaryKey and DBName are setup by the class constructor.

I execute the client.CreateDocumentQuery

But not seeing the expected cast to the out param of the function i.e. "user". I see the generated query string only.

I'm basing my code on enter image description here

If trying ReadDocumentAsync, I get the following enter image description here

CodePudding user response:

Try this, you need to return the first item

 var response = this.client.CreateDocumentQuery<eUser>( UriFactory.CreateDocumentCollectionUri("demo", "Users"), queryOptions) 
.Where(f => f.Email == email).AsEnumerable().ToArray().FirstOrDefault();
  • Related