Search code examples
c#azureazure-table-storageazure-storage-accountazure-tablequery

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


I use WindowsAzure.Storage 9.1.1 nuget package and when I run:

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);

It throws exception:

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

I think I was doing it before but now I can't. What's wrong, why am I getting this error?


Solution

  • For your query, you should use this line of code:

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

    The sample demo as below:

      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);
       }
    

    Test result as below: enter image description here

    WindowsAzure.Storage 9.1.1 nuget package screenshot: enter image description here