I have this code:
var query = _cityRepository.GetAll(
u => u.PartitionKey == pk &
u.RowKey.CompareTo(lowerBound) >= 0 &
u.RowKey.CompareTo(upperBound) < 0)
.OrderBy(item => item.RowKey.Substring(0, 3))
.ThenBy(item => item.ShortTitle)
.Select((t, index) => 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();
When I look at the data coming out I find this for the first two rows:
RowKey = 0101004O , ShortTitle = "Access 1"
RowKey = 0103004M , ShortTitle = "Access 2"
RowKey = 0101004K , ShortTitle = "xxx"
When testing I simplified this to:
var query1 = _cityRepository.GetAll()
.OrderBy(item => item.RowKey.Substring(0, 3))
.ThenBy(item => item.ShortTitle);
and the order is the same. Still the RowKey does not seem to be in the right order.
It is supposed to sort on the first four characters of the rowkey and then on the ShortTitle.
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.
You’re sorting by the first 3 characters of
rowkey, not 4. To use 4 characters, do this: