C# 使用Microsoft.Azure.Cosmos时如何获取已编译的查询

C# 使用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)

当使用nuget
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();