.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
相关产品推荐
相关产品推荐

