Fluent 方法不能在通过 CloudTable.CreateQuery<T>() 创建的查询上调用

Fluent methods may not be invoked on a Query created via CloudTable.CreateQuery<T>()

我使用 WindowsAzure.Storage 9.1.1 nuget 包,当我 运行:

var table = GetTableReference(vehicleStatusTableName);
var condition = TableQuery.CombineFilters(
            TableQuery.GenerateFilterCondition(partitionKey, QueryComparisons.Equal, vehicleId.ToString()),
            TableOperators.And,
            TableQuery.GenerateFilterCondition(rowKey, QueryComparisons.Equal, string.Empty));

var query = table.CreateQuery<VehicleStatusEntity>().Where(condition);

抛出异常:

Fluent methods may not be invoked on a Query created via CloudTable.CreateQuery()

我想我以前可以,但现在不行了。怎么了,为什么会出现这个错误?

对于您的查询,您应该使用这行代码:

  var query =new TableQuery<CustomerEntity>().Where(condition);

示例演示如下:

  CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
  CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
  CloudTable table = tableClient.GetTableReference("humans");

  var condition = TableQuery.CombineFilters(
                TableQuery.GenerateFilterCondition("PartitionKey",QueryComparisons.Equal, "Harp222"),
                TableOperators.And,
                TableQuery.GenerateFilterCondition("RowKey",QueryComparisons.Equal, "Walter222")
                );

   var query =new TableQuery<CustomerEntity>().Where(condition);

   foreach (CustomerEntity entity in table.ExecuteQuery(query))
   {
      Console.WriteLine("{0}, {1}\t{2}\t{3}", entity.PartitionKey, entity.RowKey,
                        entity.Email, entity.PhoneNumber);
   }

测试结果如下:

WindowsAzure.Storage 9.1.1 nuget 包截图: