If I have a querable from a Cosmos DB container. What's the performance impact if I write code in these two different ways?
query.Where(x=>x.a=1 && x.b=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
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.