internal static ReadOnlyCollection <DbSortClause> ValidateSortArguments( IEnumerable <DbSortClause> sortOrder) { EnumerableValidator <DbSortClause, DbSortClause, ReadOnlyCollection <DbSortClause> > validator = ArgumentValidation.CreateValidator <DbSortClause, DbSortClause, ReadOnlyCollection <DbSortClause> >(sortOrder, nameof(sortOrder), (Func <DbSortClause, int, DbSortClause>)((key, idx) => key), (Func <List <DbSortClause>, ReadOnlyCollection <DbSortClause> >)(keyList => ArgumentValidation.NewReadOnlyCollection <DbSortClause>((IList <DbSortClause>)keyList))); validator.AllowEmpty = false; return(validator.Validate()); }
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)); }