C# 使用Microsoft.Azure.Cosmos时如何获取已编译的查询
当使用nugetC# 使用Microsoft.Azure.Cosmos时如何获取已编译的查询,c#,azure,azure-cosmosdb,C#,Azure,Azure Cosmosdb,当使用nugetMicrosoft.Azure.DocumentDB及其DocumentClient类时,您可以获得将对cosmos执行的已编译查询。像这样: var documentClient = new DocumentClient(new Uri(endpoint), authKey); var query = documentClient .CreateDocumentQuery<Product>(collectionUrl, queryOptions)
Microsoft.Azure.DocumentDB
及其DocumentClient
类时,您可以获得将对cosmos执行的已编译查询。像这样:
var documentClient = new DocumentClient(new Uri(endpoint), authKey);
var query = documentClient
.CreateDocumentQuery<Product>(collectionUrl, queryOptions)
.Where(x => x.Id == "apple-iphone")
.Select(x => new
{
x.Id
})
.AsDocumentQuery();
// Here you can inspect the compiled query: "SELECT VALUE {"Id": root["id"]} FROM root WHERE (root["id"] = "apple-iphone")"
var rawQuery = query.ToString();
使用
Microsoft.Azure.cosmos
时,是否仍然可以获取将对cosmos执行的已编译查询?在调用ToFeedIterator()
之前,可以在IQueryable上调用queryable.ToQueryDefinition().QueryText
。您也可以直接调用ToString()
来获取SQL查询定义,就像在v2中一样。在调用ToFeedIterator()
之前,您可以在IQueryable
上调用queryable.ToQueryDefinition().QueryText
。您还可以直接调用ToString()
来获取SQL查询定义,就像在v2中一样
var container = new CosmosClientBuilder(endpoint, authKey)
.WithConnectionModeDirect()
.WithThrottlingRetryOptions(TimeSpan.FromSeconds(30), 10)
.Build()
.GetContainer(databaseId, collectionId);
var query = container
.GetItemLinqQueryable<Product>(requestOptions: queryOptions)
.Where(x => x.Id == "apple-iphone")
.Select(x => new
{
x.Id
})
.ToFeedIterator();
// How do I get the compiled query here???
var rawQuery = query.ToString();