My LINQ sort does not seem to be sorting the way I asked it to
<p>I have this code:</p>

<pre><code>var query = _cityRepository.GetAll(
                              u =&gt; u.PartitionKey == pk &amp;
                              u.RowKey.CompareTo(lowerBound) &gt;= 0 &amp;
                              u.RowKey.CompareTo(upperBound) &lt; 0)
               .OrderBy(item =&gt; item.RowKey.Substring(0, 3))
               .ThenBy(item =&gt; item.ShortTitle)
               .Select((t, index) =&gt; new City.Grid()
               {
                   PartitionKey = t.PartitionKey,
                   RowKey = t.RowKey,
                   Row = index + 1,
                   ShortTitle = t.ShortTitle,
                   Created = t.Created,
                   CreatedBy = t.CreatedBy,
                   Modified = t.Modified,
                   ModifiedBy = t.ModifiedBy
               })
               .ToList();
</code></pre>

<p>When I look at the data coming out I find this for the first two rows:</p>

<pre><code>RowKey = 0101004O , ShortTitle = "Access 1"
RowKey = 0103004M , ShortTitle = "Access 2"
RowKey = 0101004K , ShortTitle = "xxx"
</code></pre>

<p>When testing I simplified this to:</p>

<pre><code>        var query1 = _cityRepository.GetAll()
            .OrderBy(item =&gt; item.RowKey.Substring(0, 3))
            .ThenBy(item =&gt; item.ShortTitle);
</code></pre>

<p>and the order is the same. Still the RowKey does not seem to be in the right order. </p>

<p>It is supposed to sort on the first four characters of the rowkey and then on the ShortTitle. </p>

<p>Can anyone see why this is not working. I have looked hard but I can't see why the OrderBy and ThenBy doesn't seem to work correctly.</p>
