Esempio n. 1
0
        internal static ReadOnlyCollection <DbExpressionBinding> ValidateCrossJoin(
            IEnumerable <DbExpressionBinding> inputs,
            out TypeUsage resultType)
        {
            List <DbExpressionBinding> expressionBindingList = new List <DbExpressionBinding>();
            List <KeyValuePair <string, TypeUsage> > columns = new List <KeyValuePair <string, TypeUsage> >();
            Dictionary <string, int>          dictionary     = new Dictionary <string, int>();
            IEnumerator <DbExpressionBinding> enumerator     = inputs.GetEnumerator();
            int index = 0;

            while (enumerator.MoveNext())
            {
                DbExpressionBinding current = enumerator.Current;
                string paramName            = StringUtil.FormatIndex(nameof(inputs), index);
                if (current == null)
                {
                    throw new ArgumentNullException(paramName);
                }
                int num = -1;
                if (dictionary.TryGetValue(current.VariableName, out num))
                {
                    throw new ArgumentException(Strings.Cqt_CrossJoin_DuplicateVariableNames((object)num, (object)index, (object)current.VariableName));
                }
                expressionBindingList.Add(current);
                dictionary.Add(current.VariableName, index);
                columns.Add(new KeyValuePair <string, TypeUsage>(current.VariableName, current.VariableType));
                ++index;
            }
            if (expressionBindingList.Count < 2)
            {
                throw new ArgumentException(Strings.Cqt_CrossJoin_AtLeastTwoInputs, nameof(inputs));
            }
            resultType = ArgumentValidation.CreateCollectionOfRowResultType(columns);
            return(new ReadOnlyCollection <DbExpressionBinding>((IList <DbExpressionBinding>)expressionBindingList));
        }
Esempio n. 2
0
        internal static TypeUsage ValidateGroupBy(
            IEnumerable <KeyValuePair <string, DbExpression> > keys,
            IEnumerable <KeyValuePair <string, DbAggregate> > aggregates,
            out DbExpressionList validKeys,
            out ReadOnlyCollection <DbAggregate> validAggregates)
        {
            List <KeyValuePair <string, TypeUsage> > columns = new List <KeyValuePair <string, TypeUsage> >();
            HashSet <string> keyNames = new HashSet <string>();
            EnumerableValidator <KeyValuePair <string, DbExpression>, DbExpression, DbExpressionList> validator1 = ArgumentValidation.CreateValidator <KeyValuePair <string, DbExpression>, DbExpression, DbExpressionList>(keys, nameof(keys), (Func <KeyValuePair <string, DbExpression>, int, DbExpression>)((keyInfo, index) =>
            {
                ArgumentValidation.CheckNamed <DbExpression>(keyInfo, nameof(keys), index);
                if (!TypeHelpers.IsValidGroupKeyType(keyInfo.Value.ResultType))
                {
                    throw new ArgumentException(Strings.Cqt_GroupBy_KeyNotEqualityComparable((object)keyInfo.Key));
                }
                keyNames.Add(keyInfo.Key);
                columns.Add(new KeyValuePair <string, TypeUsage>(keyInfo.Key, keyInfo.Value.ResultType));
                return(keyInfo.Value);
            }), (Func <List <DbExpression>, DbExpressionList>)(expList => new DbExpressionList((IList <DbExpression>)expList)));

            validator1.AllowEmpty = true;
            validator1.GetName    = (Func <KeyValuePair <string, DbExpression>, int, string>)((keyInfo, idx) => keyInfo.Key);
            validKeys             = validator1.Validate();
            bool hasGroupAggregate = false;
            EnumerableValidator <KeyValuePair <string, DbAggregate>, DbAggregate, ReadOnlyCollection <DbAggregate> > validator2 = ArgumentValidation.CreateValidator <KeyValuePair <string, DbAggregate>, DbAggregate, ReadOnlyCollection <DbAggregate> >(aggregates, nameof(aggregates), (Func <KeyValuePair <string, DbAggregate>, int, DbAggregate>)((aggInfo, idx) =>
            {
                ArgumentValidation.CheckNamed <DbAggregate>(aggInfo, nameof(aggregates), idx);
                if (keyNames.Contains(aggInfo.Key))
                {
                    throw new ArgumentException(Strings.Cqt_GroupBy_AggregateColumnExistsAsGroupColumn((object)aggInfo.Key));
                }
                if (aggInfo.Value is DbGroupAggregate)
                {
                    if (hasGroupAggregate)
                    {
                        throw new ArgumentException(Strings.Cqt_GroupBy_MoreThanOneGroupAggregate);
                    }
                    hasGroupAggregate = true;
                }
                columns.Add(new KeyValuePair <string, TypeUsage>(aggInfo.Key, aggInfo.Value.ResultType));
                return(aggInfo.Value);
            }), (Func <List <DbAggregate>, ReadOnlyCollection <DbAggregate> >)(aggList => ArgumentValidation.NewReadOnlyCollection <DbAggregate>((IList <DbAggregate>)aggList)));

            validator2.AllowEmpty = true;
            validator2.GetName    = (Func <KeyValuePair <string, DbAggregate>, int, string>)((aggInfo, idx) => aggInfo.Key);
            validAggregates       = validator2.Validate();
            if (validKeys.Count == 0 && validAggregates.Count == 0)
            {
                throw new ArgumentException(Strings.Cqt_GroupBy_AtLeastOneKeyOrAggregate);
            }
            return(ArgumentValidation.CreateCollectionOfRowResultType(columns));
        }
Esempio n. 3
0
 internal static TypeUsage ValidateApply(
     DbExpressionBinding input,
     DbExpressionBinding apply)
 {
     if (input.VariableName.Equals(apply.VariableName, StringComparison.Ordinal))
     {
         throw new ArgumentException(Strings.Cqt_Apply_DuplicateVariableNames);
     }
     return(ArgumentValidation.CreateCollectionOfRowResultType(new List <KeyValuePair <string, TypeUsage> >()
     {
         new KeyValuePair <string, TypeUsage>(input.VariableName, input.VariableType),
         new KeyValuePair <string, TypeUsage>(apply.VariableName, apply.VariableType)
     }));
 }
Esempio n. 4
0
 internal static TypeUsage ValidateJoin(
     DbExpressionBinding left,
     DbExpressionBinding right,
     DbExpression joinCondition)
 {
     if (left.VariableName.Equals(right.VariableName, StringComparison.Ordinal))
     {
         throw new ArgumentException(Strings.Cqt_Join_DuplicateVariableNames);
     }
     ArgumentValidation.RequireCompatibleType(joinCondition, PrimitiveTypeKind.Boolean, nameof(joinCondition));
     return(ArgumentValidation.CreateCollectionOfRowResultType(new List <KeyValuePair <string, TypeUsage> >(2)
     {
         new KeyValuePair <string, TypeUsage>(left.VariableName, left.VariableType),
         new KeyValuePair <string, TypeUsage>(right.VariableName, right.VariableType)
     }));
 }