Using Azure Tables Storage we know that selecting primary key and row key one of the most important things. In my situation I decide to make a complex Row Key. It looks like some GUID + “_” + Other Data.
The next step is searching some data that contains first part of Row Key – GUID. For example to delete entities.
First part is prepare batch deletion. To achieve this I find great solution here.
The second part is make Expression – to filter entities using Substring or Left method. For that we can use CompareTo method.
For example I need remove users by project:
string projectIdString = projectId.ToString().ToLower(); // projectId - Guid
string startQuery = projectIdString + "_"; // Our separate symbol
string endQuery = projectIdString + "`"; // Next symbol in ASCII table after "_"
Expression<Func<DynamicTableEntity, bool>> filters = (e.RowKey.CompareTo(startQuery) >= 0 && e.RowKey.CompareTo(endQuery) < 0);
CloudTable table = _storageContext.Table(Tables.Users);
bool result = await DeleteAllEntitiesInBatches(table, filters);
Success. Now we know how to search entities using method like Substring or Left for Azure Table Storage.