0

I am getting this error while executing this query against Azure table storage:

var query = table.CreateQuery<DynamicTableEntity>()
                   .Where(d => d.PartitionKey == partitionId
                    && d.Properties["Content"].StringValue.Contains("Polly"))
                    ).AsTableQuery();
                    
                    var result = table.ExecuteQuery<DynamicTableEntity>(query);

                    foreach (var entity in result)
                        {
                         //Do stuff             
                        }

The error happens when executing this line:

foreach (var entity in result)

Now, the error and stacktrace are not very useful, but I was able to determine that the error is caused by the inclusion of this condition:

d.Properties["Content"].StringValue.Contains("Polly")

Remove this line and the problem disappear.

There is some sort of limitation about the usage of methods like "Contains" in a TableQuery? If so there is any workaround, so that I can filter the rows that contain a given string in the field "Content"?

Art
  • 163
  • 1
  • 8

1 Answers1

0

There is some sort of limitation about the usage of methods like "Contains" in a TableQuery?

This is correct. Azure Table Storage has support for limited number of LINQ operators and Contains is not one of them. For the list of support LINQ operators please see this link: https://learn.microsoft.com/en-us/rest/api/storageservices/query-operators-supported-for-the-table-service.

Gaurav Mantri
  • 128,066
  • 12
  • 206
  • 241
  • I thought that may be the case. So there is any workaround, way to achieve the same result? The only one I can think about is doing the table query without that filter, convert to result to a list, and then do a linq filter with the entities loaded in memory. But The problem is that this way seems a very inefficient way to perform the query, since the result is not filtered at database level, and potentially a lot of data will be loaded in memory. – Art Oct 17 '22 at 14:07
  • Client side filtering (like you mentioned) is the only way to accomplish this. – Gaurav Mantri Oct 17 '22 at 15:22