How can I see the document DB sql query (in a string) generated by a linq statement before it gets sent to the server?
_documentClient.CreateDocumentQuery<MyType>(
UriFactory.CreateDocumentCollectionUri(DatabaseName,
CollectionName)).Where(....).SelectMany(...)
I want to use this for tracing purposes.
You can get same generated SQL query manually by calling ToString: string sql = committeeMember. ToString(); This overridden method internally calls ObjectQuery.
In a LINQ query, you are always working with objects. You use the same basic coding patterns to query and transform data in XML documents, SQL databases, ADO.NET Datasets, . NET collections, and any other format for which a LINQ provider is available.
A linq provider is software that implements the IQueryProvider and IQueryable interfaces for a particular data store. In other words, it allows you to write Linq queries against that data store. For example, the Linq to XML provider allows you to write Linq queries against XML documents.
You can call ToString() on the DocumentDB query to get the SQL translation of the LINQ expression that's sent over the wire.
string sql = client.CreateDocumentQuery<MyType>(collectionUri).Where(t => t.Name = "x").ToString();
// sql is somthing like SELECT * FROM c WHERE c["Name"] = "x"
You could just use Fiddler and view the JSON of the request after it is sent.
View an example here:
CosmosDB\DocumentDB Generated SQL Query
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With