我正在尝试使用Microsoft.Azure.Management.Compute
'sComputeManagementClient
来查询ResourceSKU。但我无法为过滤器参数提供正确的值。如果没有过滤器,响应会非常大,我想通过使用 resourceType = virtualMachines 进行过滤来减少它。
更具体地说,这是我的代码:
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);
知道什么是正确的格式吗?