Here is an example of using the GreaterThanOrEqual
and LessThan
operators as an extension of the target column name.
The filter combines two parts:
- anything that is greater than or equal to your start with a prefix,
- add the last character of your prefix and find something less.
For example, the prefix startsWith
"CAR" will prepare something like s >= "CAR" && s < "CAS"
.
public static string GetStartsWithFilter(this string columnName, string startsWith) { var length = startsWith.Length - 1; var nextChar = startsWith[length] + 1; var startWithEnd = startsWith.Substring(0, length) + (char)nextChar; var filter = TableQuery.CombineFilters( TableQuery.GenerateFilterCondition(columnName, QueryComparisons.GreaterThanOrEqual, startsWith), TableOperators.And, TableQuery.GenerateFilterCondition(columnName, QueryComparisons.LessThan, startWithEnd)); return filter; }
Using:
var query = new TableQuery<MyTableEntity>().Where(myColumnName.GetStartsWithFilter(prefix));
Based on Alexandre B Blog
source share