0

We have a storage table where we want to add a new integer column (It is in fact an enum of 3 values converted to int). We want a row to be required when:

  1. It is an older row and the column does not exist
  2. It is a new row and the column exists and does not match a particular value

When I just use a not equal operator on the column the old rows do not get returned. How can this be handled?

Update

Assuming a comparison always returns false for the non-existent column I tried somethinglike below (the value of the property will be always > 0 when it exists), which does not work either:

If the (Prop GreaterThanOrEqual -1) condition returns false I assume the value is null.

If not then, the actual comparison happens.

string propNullCondition = TableQuery.GenerateFilterConditionForInt(
                    "Prop",
                    QueryComparisons.GreaterThanOrEqual,
                    -1);

propNullCondition = $"{TableOperators.Not}({propNullCondition})";

string propNotEqualValueCondition = TableQuery.CombineFilters(
            propNullCondition,
            TableOperators.Or,
            TableQuery.GenerateFilterConditionForInt(
                "Prop",
                QueryComparisons.NotEqual,
                XXXX));

Note: The table rows written so far do not have "Prop" and only new rows will have this column. And expectation is the query should return all old rows and the new ones only when Prop != XXXX.

Sayantan Ghosh
  • 998
  • 2
  • 9
  • 29

1 Answers1

0

It seems that your code is correct, maybe there is a minor error there. You can follow my code below, which works fine as per my test:

Note: in the filter, the column name is case-sensitive.

        CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
        CloudTable table = tableClient.GetTableReference("test1");

        string propNullCondition = TableQuery.GenerateFilterConditionForInt(
                "prop1", //note the column name shoud be case-sensitive here.
                QueryComparisons.GreaterThanOrEqual,
                -1);

        propNullCondition = $"{TableOperators.Not}({propNullCondition})";

        TableQuery<DynamicTableEntity> propNotEqualValueCondition = new TableQuery<DynamicTableEntity>()
            .Where(
             TableQuery.CombineFilters(
                propNullCondition,
                TableOperators.Or,
                TableQuery.GenerateFilterConditionForInt(
                "prop1",//note the column name shoud be case-sensitive here.
                QueryComparisons.NotEqual,
                2)));
            
    
        var query = table.ExecuteQuery(propNotEqualValueCondition);

        foreach (var q in query)
        {
            Console.WriteLine(q.PartitionKey);
        }

The test result:

enter image description here

Here is my table in azure:

enter image description here

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