我正在尝试使用Microsoft.Azure.Management.Compute
的ComputeManagementClient
来查询资源SKU。但是我无法为过滤器参数提供正确的值。如果没有过滤器,响应会非常大,我想通过使用 resourceType = 虚拟机进行过滤来减少它。
更具体地说,这是我的代码:
ComputeManagementClient computeManagementClient = new ComputeManagementClient(credentials);
computeManagementClient.SubscriptionId = "**********";
string filter = "resourceType eq 'virtualMachines'"; // Doesn't work. All results are returned.
// string filter = "$filter=resourceType eq 'virtualMachines'"; // Doesn't work. All results are returned.
// string filter = "resourceType eq virtualMachines"; // Doesn't work. All results are returned.
// string filter = "resourceType eq 'Microsoft.Compute/virtualMachines'"; // Doesn't work. All results are returned.
// string filter = "resourceType = 'virtualMachines'"; // Doesn't work. All results are returned.
// string filter = "resourceType='virtualMachines'"; // Doesn't work. All results are returned.
IPage<ResourceSku> resourceSkus = await computeManagementClient.ResourceSkus.ListAsync(filter: filter);
我还尝试使用OData.FilterString.Generate
生成过滤器字符串:
Expression<Func<ResourceSku, bool>> filterPredicate = x => x.ResourceType.Equals("virtualMachines", StringComparison.OrdinalIgnoreCase);
string filter = FilterString.Generate(filterPredicate);
IPage<ResourceSku> resourceSkus = await computeManagementClient.ResourceSkus.ListAsync(filter: filter);
知道正确的格式是什么吗?
根据我的研究,ResourceSkus API 仅支持按区域过滤。有关更多详细信息,请参阅反馈和文章