You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET函数应用中CosmosDB DateTime查询无结果问题排查

问题排查:CosmosDB查询在.NET函数应用中返回0结果

我需要获取处于Creating状态超过4小时的虚拟机,该查询在CosmosDB中执行正常,但在.NET函数应用中返回0条结果。以下是相关代码、示例数据和方法实现,请求协助排查。

查询代码

var comparableDate = DateTime.UtcNow.AddHours(-4);
var query = this._repo.GetItemsQuery(poolId)
     .Where(vm =>
     vm.PoolId.Equals(poolId) &&
     vm.LabId.Equals(labId) &&
     (vm.State == ResourceState.Creating && vm.CreatedTime < comparableDate)
     );

应返回的示例数据

[
  {
    "SubscriptionId": "<subscriptionId>",
    "ResourceGroupName": "tb-med-rg-ppe-0-bl-2",
    "Region": "eastus",
    "LabName": "<LabName>",
    "VmName": "<VMName>",
    "PoolId": "<PoolId>",
    "LabId": "<LabId>",
    "State": "Creating",
    "CreatedTime": "2022-12-09T11:18:32.8312471Z",
    "LabCreatedTime": null,
    "PrivateIPAddress": null,
    "LeaseId": "<leaseId>",
    "LeasedUntil": "2022-12-09T15:18:32.8323785Z",
    "id": "<id>"
  },
  {
    "SubscriptionId": "<subscriptionId>",
    "ResourceGroupName": "tb-med-rg-ppe-0-bl-2",
    "Region": "eastus",
    "LabName": "<LabName>",
    "VmName": "<VMName>",
    "PoolId": "<PoolId>",
    "LabId": "<LabId>",
    "State": "Creating",
    "CreatedTime": "2022-12-09T13:45:16.996413Z",
    "LabCreatedTime": null,
    "PrivateIPAddress": null,
    "LeaseId": "<leaseId>",
    "LeasedUntil": "2022-12-09T17:45:16.9973301Z",
    "id": "<id>"
  },
  {
    "SubscriptionId": "<subscriptionId>",
    "ResourceGroupName": "tb-med-rg-ppe-0-bl-2",
    "Region": "eastus",
    "LabName": "<LabName>",
    "VmName": "<VMName>",
    "PoolId": "<PoolId>",
    "LabId": "<LabId>",
    "State": "Creating",
    "CreatedTime": "2022-12-09T17:12:10.3620983Z",
    "LabCreatedTime": null,
    "PrivateIPAddress": null,
    "LeaseId": "<leaseId>",
    "LeasedUntil": "2022-12-09T21:12:10.3653741Z",
    "id": "<id>"
  }
]

GetItemsQuery方法实现

public IQueryable<T> GetItemsQuery(string partitionKey = "")
{
       var container = this.containerFactory.GetContainer(this.ContainerProperties.Id);
       QueryRequestOptions options = new QueryRequestOptions
            {
                PartitionKey = new PartitionKey(partitionKey),
            };

            return container.GetItemLinqQueryable<T>(true, null, options);
}

内容的提问来源于stack exchange,提问作者Richa Dua

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.08 23:50:33