0

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 this

public void  GetUserByEmail(string email, out IQueryable<Shared.User> user)
    {
        FeedOptions queryOptions = new FeedOptions { MaxItemCount = -1 };
        user = null;

        try
        { 
            user = this.client.CreateDocumentQuery<Shared.User>(
                       UriFactory.CreateDocumentCollectionUri(DBName, "Users"), queryOptions)
                       .Where(f => f.Email == email);
        }
        catch (Exception ex)
        {
        }

    }

enter image description here

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

4
  • Have you tried executing the query in portal? with same email id? Commented Feb 21, 2022 at 10:55
  • SELECT * FROM c shows me my json, i.e. { "UserName": "[email protected]", "Email": "[email protected]", "Password": "P@ssw0rd1", "Role": { "id": "1", "Role": "Admin" }, "id": "d3e4351d-79fc-469f-8c22-8735e6f3fe71" } Commented Feb 21, 2022 at 10:58
  • add the where clause and see if its returning the data Commented Feb 21, 2022 at 11:16
  • If I use SELECT * FROM c WHERE c.id = "d3e4351d-79fc-469f-8c22-8735e6f3fe71" then it works in the portal, but it won't allow me to specify the where with the emailaddress Commented Feb 21, 2022 at 11:28

1 Answer 1

1

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();
Sign up to request clarification or add additional context in comments.

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.