Пример #1
0
        private static Func <GenericTableEntity, bool> FilterByKeyRange(Func <GenericTableEntity, string> getKey, KeyRange keyRange)
        {
            if (keyRange.IsSingleValue())
            {
                return(e => getKey(e) == keyRange.SingleValue());
            }
            Func <GenericTableEntity, bool> lowerFilter = e => true;

            if (keyRange.Lower.HasValue)
            {
                var bound = keyRange.Lower.Value;
                lowerFilter = e => bound.IsInclusive ? Compare(getKey(e), bound) >= 0 : Compare(getKey(e), bound) > 0;
            }
            Func <GenericTableEntity, bool> upperFilter = e => true;

            if (keyRange.Upper.HasValue)
            {
                var bound = keyRange.Upper.Value;
                upperFilter = e => bound.IsInclusive ? Compare(getKey(e), bound) <= 0 : Compare(getKey(e), bound) < 0;
            }
            return(e => lowerFilter(e) && upperFilter(e));
        }
Пример #2
0
        private static string BuildFilterExpr(string keyName, KeyRange keyRange)
        {
            if (keyRange.IsSingleValue())
            {
                return(TableQuery.GenerateFilterCondition(keyName, QueryComparisons.Equal, keyRange.SingleValue()));
            }

            var expr = "";

            if (keyRange.Lower.HasValue)
            {
                var op = keyRange.Lower.Value.IsInclusive
                        ? QueryComparisons.GreaterThanOrEqual
                        : QueryComparisons.GreaterThan;
                expr = TableQuery.GenerateFilterCondition(keyName, op, keyRange.Lower.Value.Value);
            }
            if (keyRange.Upper.HasValue)
            {
                var op = keyRange.Upper.Value.IsInclusive
                        ? QueryComparisons.LessThanOrEqual
                        : QueryComparisons.LessThan;
                var ltExpr = TableQuery.GenerateFilterCondition(keyName, op, keyRange.Upper.Value.Value);
                expr = string.IsNullOrEmpty(expr) ? ltExpr : TableQuery.CombineFilters(expr, TableOperators.And, ltExpr);
            }
            return(expr);
        }