1

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?

Andrei
  • 42,814
  • 35
  • 154
  • 218
  • Hi Andrei, is the answer below working for you? You can find more details at this [page](https://blogs.msdn.microsoft.com/windowsazurestorage/2013/09/06/announcing-storage-client-library-2-1-rtm-ctp-for-windows-phone/) -> "Conceptual model" section. – Ivan Glasenberg Oct 12 '18 at 00:59
  • Does the answer work for you? if yes, could you please help mark it as answer? – Ivan Glasenberg Oct 29 '18 at 05:24
  • @IvanYang it didn't unfortunately. But thanks for your answer. The code in your answer is not any different from the code that I have in my question. I'll post my answer later. – Andrei Oct 29 '18 at 15:28
  • ok, but it works at my side if use the `var query =new TableQuery().Where(condition);` – Ivan Glasenberg Oct 29 '18 at 22:35
  • @IvanYang did you try it with specified version of nuget package? – Andrei Oct 30 '18 at 02:52
  • Yes, it's `WindowsAzure.Storage 9.1.1` . I have post the screenshot at the end of the answer. – Ivan Glasenberg Oct 30 '18 at 03:04
  • @IvanYang you know, it wasn't really working for my solution at work for some strange reason but it does work on all my other projects, and you're the only answer so I'll accept. Thanks for your help! – Andrei Oct 30 '18 at 14:49

1 Answers1

0

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

Ivan Glasenberg
  • 29,865
  • 2
  • 44
  • 60