Note that there are some explanatory texts on larger screens.

plurals
  1. POAzure table storage range query with commonly used condition wrapped in method
    text
    copied!<p>I have a common occurence in my application where I create a query to get all entities where partitionkey is constant but rowkey should be within an lexical range (e.g. only rows which start with some prefix):</p> <pre><code>//query to get all entities in partition "KnownPartition" where RowKey starts with "Prefix_" CloudTableQuery&lt;MyEntity&gt; query = (from e in tableServiceContext.CreateQuery&lt;MyEntity&gt;(tableName) where e.PartitionKey == "KnownPartition" &amp;&amp; e.RowKey.CompareTo("Prefix_") &gt; 0 &amp;&amp; e.RowKey.CompareTo("Prefix`") &lt;= 0 // ` is '_' + 1 select e).AsTableServiceQuery(); </code></pre> <p>I must use CompareTo because string functions such as StartsWith are not supported in this kind of query. This works, but the condition is hard to read and repeated a lot. So instead of writing a lot of queries with this hard-to-read condition, I'd rather like to make a function which "inlined" it:</p> <pre><code>public static Boolean HasPrefix(this String rowKey, String prefix) { return rowKey.CompareTo(prefix + '_') &gt; 0 &amp;&amp; rowKey.CompareTo(prefix + '`') &lt;= 0; } CloudTableQuery&lt;MyEntity&gt; query = (from e in tableServiceContext.CreateQuery&lt;MyEntity&gt;(tableName) where e.PartitionKey == "KnownPartition" &amp;&amp; e.RowKey.HasPrefix("Prefix") select e).AsTableServiceQuery(); </code></pre> <p>But when I run this, I get an exception from Azure about my function not being supported. Is there any way to write this so that it is supported? After all, I'm using the exact same condition as the query that worked, just wrapped in a function...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload