// If RowKeyStart/RowKeyEnd are null, then it's an open ended query. public static TableQuery <T> WhereRowRange <T>( this TableQuery <T> query, string partitionKey, string rowKeyStart = null, string rowKeyEnd = null ) where T : TableEntity { if (partitionKey == null) { throw new ArgumentNullException(nameof(partitionKey)); } string filter = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partitionKey); if (rowKeyStart != null) { filter = TableQuery.CombineFilters(filter, TableOperators.And, TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.GreaterThanOrEqual, rowKeyStart)); } if (rowKeyEnd != null) { filter = TableQuery.CombineFilters(filter, TableOperators.And, TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.LessThanOrEqual, rowKeyEnd)); } return(query.AppendWhere(filter)); }
public static TableQuery <T> WhereEquals <T>( this TableQuery <T> query, string propertyName, object value ) where T : TableEntity { var prop = typeof(T).GetProperty(propertyName); if (prop == null) { throw new ArgumentException($"No property '{propertyName}' on type '{typeof(T).Name}'"); } string filter; if (prop.PropertyType == typeof(string)) { filter = TableQuery.GenerateFilterCondition( propertyName, QueryComparisons.Equal, (string)value); } else if (prop.PropertyType == typeof(int)) { filter = TableQuery.GenerateFilterConditionForInt( propertyName, QueryComparisons.Equal, (int)value); } else if (prop.PropertyType == typeof(bool)) { filter = TableQuery.GenerateFilterConditionForBool( propertyName, QueryComparisons.Equal, (bool)value); } else { throw new ArgumentException($"Unsupported type '{prop.PropertyType.Name}' for property '{propertyName}'"); } return(query.AppendWhere(filter)); }