0

If I have a querable from a Cosmos DB container. What's the performance impact if I write code in these two different ways?

  1. query.Where(x=>x.a=1 && x.b=2);
  2. query.Where(x=>x.a=1).Where(x=>x.b=2);

I tried to get the query expression with query.Expression.ToString(), but the output is still very c# code like, not sql-like. So, I don't know what kind of query it will execute on the server side.

Would the two queries generate same/similar server side query?

Is there a way to get the generated sql query like they did in this document?

Thanks

1
  • I would suggest benchmarking and evaluating the RU cost of each, along with total time of each. I really don't think there's an absolute answer, aside from benchmark. That aside: it's unclear what document you're referring to, as your link is to a fairly long article. All details should be here in your question, so it's a good idea to include a sample document here. Commented Dec 5, 2024 at 4:20

1 Answer 1

2

You could try to parse your delegate (Func<>) of IQueryable<> to string to get the desired result.

The LINQ provider for Cosmos DB will combine the conditions into a single WHERE clause on the server side, regardless of whether you used one .Where() or multiple chained calls.

Both your examples will generate the same query:

SELECT * FROM c WHERE c.a = 1 AND c.b = 2

The Cosmos DB LINQ provider is good enough in optimizing the query translation, so you can safely operate the both options.

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.