internal DbArithmeticExpression(DbExpressionKind kind, TypeUsage numericResultType, DbExpressionList args)
            : base(kind, numericResultType)
        {
            Debug.Assert(TypeSemantics.IsNumericType(numericResultType), "DbArithmeticExpression result type must be numeric");

            Debug.Assert(
                DbExpressionKind.Divide == kind ||
                DbExpressionKind.Minus == kind ||
                DbExpressionKind.Modulo == kind ||
                DbExpressionKind.Multiply == kind ||
                DbExpressionKind.Plus == kind ||
                DbExpressionKind.UnaryMinus == kind,
                "Invalid DbExpressionKind used in DbArithmeticExpression: " + Enum.GetName(typeof(DbExpressionKind), kind)
                );

            Debug.Assert(args != null, "DbArithmeticExpression arguments cannot be null");

            Debug.Assert(
                (DbExpressionKind.UnaryMinus == kind && 1 == args.Count) ||
                2 == args.Count,
                "Incorrect number of arguments specified to DbArithmeticExpression"
                );

            this._args = args;
        }
示例#2
0
        internal static TypeUsage ValidateNewEntityWithRelationships(
            EntityType entityType,
            IEnumerable <DbExpression> attributeValues,
            IList <DbRelatedEntityRef> relationships,
            out DbExpressionList validArguments,
            out ReadOnlyCollection <DbRelatedEntityRef> validRelatedRefs)
        {
            TypeUsage typeUsage = ArgumentValidation.ValidateNew(ArgumentValidation.CreateResultType((EdmType)entityType), attributeValues, out validArguments);

            if (relationships.Count > 0)
            {
                List <DbRelatedEntityRef> relatedEntityRefList = new List <DbRelatedEntityRef>(relationships.Count);
                for (int index = 0; index < relationships.Count; ++index)
                {
                    DbRelatedEntityRef relationship = relationships[index];
                    EntityTypeBase     elementType  = TypeHelpers.GetEdmType <RefType>(relationship.SourceEnd.TypeUsage).ElementType;
                    if (!entityType.EdmEquals((MetadataItem)elementType) && !entityType.IsSubtypeOf((EdmType)elementType))
                    {
                        throw new ArgumentException(Strings.Cqt_NewInstance_IncompatibleRelatedEntity_SourceTypeNotValid, StringUtil.FormatIndex(nameof(relationships), index));
                    }
                    relatedEntityRefList.Add(relationship);
                }
                validRelatedRefs = new ReadOnlyCollection <DbRelatedEntityRef>((IList <DbRelatedEntityRef>)relatedEntityRefList);
            }
            else
            {
                validRelatedRefs = new ReadOnlyCollection <DbRelatedEntityRef>((IList <DbRelatedEntityRef>) new DbRelatedEntityRef[0]);
            }
            return(typeUsage);
        }
示例#3
0
        internal DbFunctionAggregate(TypeUsage resultType, DbExpressionList arguments, EdmFunction function, bool isDistinct)
            : base(resultType, arguments)
        {
            DebugCheck.NotNull(function);

            _aggregateFunction = function;
            _distinct          = isDistinct;
        }
 internal DbNewInstanceExpression(
     TypeUsage resultType,
     DbExpressionList attributeValues,
     ReadOnlyCollection <DbRelatedEntityRef> relationships)
     : this(resultType, attributeValues)
 {
     this._relatedEntityRefs = relationships.Count > 0 ? relationships : (ReadOnlyCollection <DbRelatedEntityRef>)null;
 }
 internal DbArithmeticExpression(
     DbExpressionKind kind,
     TypeUsage numericResultType,
     DbExpressionList args)
     : base(kind, numericResultType, true)
 {
     this._args = args;
 }
示例#6
0
        internal DbAggregate(TypeUsage resultType, DbExpressionList arguments)
        {
            DebugCheck.NotNull(resultType);
            DebugCheck.NotNull(arguments);

            _type = resultType;
            _args = arguments;
        }
示例#7
0
        internal DbFunctionAggregate(TypeUsage resultType, DbExpressionList arguments, EdmFunction function, bool isDistinct)
            : base(resultType, arguments)
        {
            Debug.Assert(function != null, "DbFunctionAggregate.Function cannot be null");

            _aggregateFunction = function;
            _distinct          = isDistinct;
        }
示例#8
0
        internal DbNewInstanceExpression(TypeUsage resultType, DbExpressionList attributeValues, System.Collections.ObjectModel.ReadOnlyCollection <DbRelatedEntityRef> relationships)
            : this(resultType, attributeValues)
        {
            Debug.Assert(TypeSemantics.IsEntityType(resultType), "An entity type is required to create a NewEntityWithRelationships expression");
            Debug.Assert(relationships != null, "Related entity ref collection cannot be null");

            this._relatedEntityRefs = (relationships.Count > 0 ? relationships : null);
        }
示例#9
0
        internal DbFunctionAggregate(TypeUsage resultType, DbExpressionList arguments, EdmFunction function, bool isDistinct)
            : base(resultType, arguments)
        {
            Debug.Assert(function != null, "DbFunctionAggregate.Function cannot be null");

            _aggregateFunction = function;
            _distinct = isDistinct;
        }
        internal DbFunctionAggregate(TypeUsage resultType, DbExpressionList arguments, EdmFunction function, bool isDistinct)
            : base(resultType, arguments)
        {
            DebugCheck.NotNull(function);

            _aggregateFunction = function;
            _distinct = isDistinct;
        }
示例#11
0
        internal DbNewInstanceExpression(TypeUsage type, DbExpressionList args)
            : base(DbExpressionKind.NewInstance, type)
        {
            Debug.Assert(args != null, "DbNewInstanceExpression arguments cannot be null");
            Debug.Assert(args.Count > 0 || TypeSemantics.IsCollectionType(type), "DbNewInstanceExpression requires at least one argument when not creating an empty collection");

            this._elements = args;
        }
示例#12
0
        internal DbAggregate(TypeUsage resultType, DbExpressionList arguments)
        {
            DebugCheck.NotNull(resultType);
            DebugCheck.NotNull(arguments);
            Debug.Assert(arguments.Count == 1, "DbAggregate requires a single argument");

            _type = resultType;
            _args = arguments;
        }
示例#13
0
        internal DbAggregate(TypeUsage resultType, DbExpressionList arguments)
        {
            Debug.Assert(resultType != null, "DbAggregate.ResultType cannot be null");
            Debug.Assert(arguments != null, "DbAggregate.Arguments cannot be null");
            Debug.Assert(arguments.Count == 1, "DbAggregate requires a single argument");

            this._type = resultType;
            this._args = arguments;
        }
        internal DbAggregate(TypeUsage resultType, DbExpressionList arguments)
        {
            DebugCheck.NotNull(resultType);
            DebugCheck.NotNull(arguments);
            Debug.Assert(arguments.Count == 1, "DbAggregate requires a single argument");

            _type = resultType;
            _args = arguments;
        }
示例#15
0
 internal DbFunctionExpression(
     TypeUsage resultType,
     EdmFunction function,
     DbExpressionList arguments)
     : base(DbExpressionKind.Function, resultType, true)
 {
     this._functionInfo = function;
     this._arguments    = arguments;
 }
示例#16
0
        internal DbAggregate(TypeUsage resultType, DbExpressionList arguments)
        {
            Debug.Assert(resultType != null, "DbAggregate.ResultType cannot be null");
            Debug.Assert(arguments != null, "DbAggregate.Arguments cannot be null");
            Debug.Assert(arguments.Count == 1, "DbAggregate requires a single argument");

            this._type = resultType;
            this._args = arguments;
        }
示例#17
0
        internal DbFunctionExpression(TypeUsage resultType, EdmFunction function, DbExpressionList arguments)
            : base(DbExpressionKind.Function, resultType)
        {
            Debug.Assert(function != null, "DbFunctionExpression function cannot be null");
            Debug.Assert(arguments != null, "DbFunctionExpression arguments cannot be null");
            Debug.Assert(object.ReferenceEquals(resultType, function.ReturnParameter.TypeUsage), "DbFunctionExpression result type must be function return type");

            this._functionInfo = function;
            this._arguments    = arguments;
        }
示例#18
0
        internal DbNewInstanceExpression(
            TypeUsage resultType, DbExpressionList attributeValues, ReadOnlyCollection <DbRelatedEntityRef> relationships)
            : this(resultType, attributeValues)
        {
            Debug.Assert(
                TypeSemantics.IsEntityType(resultType), "An entity type is required to create a NewEntityWithRelationships expression");
            DebugCheck.NotNull(relationships);

            _relatedEntityRefs = (relationships.Count > 0 ? relationships : null);
        }
示例#19
0
 internal DbFunctionAggregate(
     TypeUsage resultType,
     DbExpressionList arguments,
     EdmFunction function,
     bool isDistinct)
     : base(resultType, arguments)
 {
     this._aggregateFunction = function;
     this._distinct          = isDistinct;
 }
示例#20
0
 internal DbGroupByExpression(
     TypeUsage collectionOfRowResultType,
     DbGroupExpressionBinding input,
     DbExpressionList groupKeys,
     ReadOnlyCollection <DbAggregate> aggregates)
     : base(DbExpressionKind.GroupBy, collectionOfRowResultType, true)
 {
     this._input      = input;
     this._keys       = groupKeys;
     this._aggregates = aggregates;
 }
示例#21
0
        internal DbLambdaExpression(TypeUsage resultType, DbLambda lambda, DbExpressionList args)
            : base(DbExpressionKind.Lambda, resultType)
        {
            Debug.Assert(lambda != null, "DbLambdaExpression lambda cannot be null");
            Debug.Assert(args != null, "DbLambdaExpression arguments cannot be null");
            Debug.Assert(object.ReferenceEquals(resultType, lambda.Body.ResultType), "DbLambdaExpression result type must be Lambda body result type");
            Debug.Assert(lambda.Variables.Count == args.Count, "DbLambdaExpression argument count does not match Lambda parameter count");

            this._lambda    = lambda;
            this._arguments = args;
        }
 internal DbCaseExpression(
     TypeUsage commonResultType,
     DbExpressionList whens,
     DbExpressionList thens,
     DbExpression elseExpr)
     : base(DbExpressionKind.Case, commonResultType, true)
 {
     this._when = whens;
     this._then = thens;
     this._else = elseExpr;
 }
示例#23
0
        internal DbLambdaExpression(TypeUsage resultType, DbLambda lambda, DbExpressionList args)
            : base(DbExpressionKind.Lambda, resultType)
        {
            DebugCheck.NotNull(lambda);
            DebugCheck.NotNull(args);
            Debug.Assert(
                ReferenceEquals(resultType, lambda.Body.ResultType), "DbLambdaExpression result type must be Lambda body result type");
            Debug.Assert(lambda.Variables.Count == args.Count, "DbLambdaExpression argument count does not match Lambda parameter count");

            _lambda    = lambda;
            _arguments = args;
        }
        internal DbCaseExpression(TypeUsage commonResultType, DbExpressionList whens, DbExpressionList thens, DbExpression elseExpr)
            : base(DbExpressionKind.Case, commonResultType)
        {
            Debug.Assert(whens != null, "DbCaseExpression whens cannot be null");
            Debug.Assert(thens != null, "DbCaseExpression thens cannot be null");
            Debug.Assert(elseExpr != null, "DbCaseExpression else cannot be null");
            Debug.Assert(whens.Count == thens.Count, "DbCaseExpression whens count must match thens count");

            this._when = whens;
            this._then = thens;
            this._else = elseExpr;
        }
        internal DbCaseExpression(TypeUsage commonResultType, DbExpressionList whens, DbExpressionList thens, DbExpression elseExpr)
            : base(DbExpressionKind.Case, commonResultType)
        {
            DebugCheck.NotNull(whens);
            DebugCheck.NotNull(thens);
            DebugCheck.NotNull(elseExpr);
            Debug.Assert(whens.Count == thens.Count, "DbCaseExpression whens count must match thens count");

            _when = whens;
            _then = thens;
            _else = elseExpr;
        }
示例#26
0
        internal DbFunctionExpression(TypeUsage resultType, EdmFunction function, DbExpressionList arguments)
            : base(DbExpressionKind.Function, resultType)
        {
            DebugCheck.NotNull(function);
            DebugCheck.NotNull(arguments);
            Debug.Assert(
                ReferenceEquals(resultType, function.ReturnParameter.TypeUsage),
                "DbFunctionExpression result type must be function return type");

            _functionInfo = function;
            _arguments    = arguments;
        }
示例#27
0
 internal static TypeUsage ValidateNewEmptyCollection(
     TypeUsage collectionType,
     out DbExpressionList validElements)
 {
     ArgumentValidation.CheckType(collectionType, nameof(collectionType));
     if (!TypeSemantics.IsCollectionType(collectionType))
     {
         throw new ArgumentException(Strings.Cqt_NewInstance_CollectionTypeRequired, nameof(collectionType));
     }
     validElements = new DbExpressionList((IList <DbExpression>) new DbExpression[0]);
     return(collectionType);
 }
示例#28
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));
        }
示例#29
0
        internal DbInExpression(TypeUsage booleanResultType, DbExpression item, DbExpressionList list)
            : base(DbExpressionKind.In, booleanResultType)
        {
            DebugCheck.NotNull(item);
            DebugCheck.NotNull(list);
            Debug.Assert(TypeSemantics.IsBooleanType(booleanResultType), "DbInExpression must have a Boolean result type");
            Debug.Assert(
                list.All(e => TypeSemantics.IsEqual(e.ResultType, item.ResultType)),
                "DbInExpression requires the same result type for the input expressions");

            _item = item;
            _list = list;
        }
示例#30
0
        internal DbGroupByExpression(TypeUsage collectionOfRowResultType,
                                     DbGroupExpressionBinding input,
                                     DbExpressionList groupKeys,
                                     System.Collections.ObjectModel.ReadOnlyCollection <DbAggregate> aggregates)
            : base(DbExpressionKind.GroupBy, collectionOfRowResultType)
        {
            Debug.Assert(input != null, "DbGroupExpression input cannot be null");
            Debug.Assert(groupKeys != null, "DbGroupExpression keys cannot be null");
            Debug.Assert(aggregates != null, "DbGroupExpression aggregates cannot be null");
            Debug.Assert(groupKeys.Count > 0 || aggregates.Count > 0, "At least one key or aggregate is required");

            _input      = input;
            _keys       = groupKeys;
            _aggregates = aggregates;
        }
示例#31
0
        internal static TypeUsage ValidateInvoke(
            DbLambda lambda,
            IEnumerable <DbExpression> arguments,
            out DbExpressionList validArguments)
        {
            validArguments = (DbExpressionList)null;
            EnumerableValidator <DbExpression, DbExpression, DbExpressionList> validator = ArgumentValidation.CreateValidator <DbExpression, DbExpression, DbExpressionList>(arguments, nameof(arguments), (Func <DbExpression, int, DbExpression>)((exp, idx) =>
            {
                ArgumentValidation.RequireCompatibleType(exp, lambda.Variables[idx].ResultType, nameof(arguments), idx);
                return(exp);
            }), (Func <List <DbExpression>, DbExpressionList>)(expList => new DbExpressionList((IList <DbExpression>)expList)));

            validator.ExpectedElementCount = lambda.Variables.Count;
            validArguments = validator.Validate();
            return(lambda.Body.ResultType);
        }
示例#32
0
        internal static TypeUsage ValidateNewRow(
            IEnumerable <KeyValuePair <string, DbExpression> > columnValues,
            out DbExpressionList validElements)
        {
            List <KeyValuePair <string, TypeUsage> > columnTypes = new List <KeyValuePair <string, TypeUsage> >();
            EnumerableValidator <KeyValuePair <string, DbExpression>, DbExpression, DbExpressionList> validator = ArgumentValidation.CreateValidator <KeyValuePair <string, DbExpression>, DbExpression, DbExpressionList>(columnValues, nameof(columnValues), (Func <KeyValuePair <string, DbExpression>, int, DbExpression>)((columnValue, idx) =>
            {
                ArgumentValidation.CheckNamed <DbExpression>(columnValue, nameof(columnValues), idx);
                columnTypes.Add(new KeyValuePair <string, TypeUsage>(columnValue.Key, columnValue.Value.ResultType));
                return(columnValue.Value);
            }), (Func <List <DbExpression>, DbExpressionList>)(expList => new DbExpressionList((IList <DbExpression>)expList)));

            validator.GetName = (Func <KeyValuePair <string, DbExpression>, int, string>)((columnValue, idx) => columnValue.Key);
            validElements     = validator.Validate();
            return(ArgumentValidation.CreateResultType((EdmType)TypeHelpers.CreateRowType((IEnumerable <KeyValuePair <string, TypeUsage> >)columnTypes)));
        }
        internal DbGroupByExpression(
            TypeUsage collectionOfRowResultType,
            DbGroupExpressionBinding input,
            DbExpressionList groupKeys,
            ReadOnlyCollection <DbAggregate> aggregates)
            : base(DbExpressionKind.GroupBy, collectionOfRowResultType)
        {
            DebugCheck.NotNull(input);
            DebugCheck.NotNull(groupKeys);
            DebugCheck.NotNull(aggregates);
            Debug.Assert(groupKeys.Count > 0 || aggregates.Count > 0, "At least one key or aggregate is required");

            _input      = input;
            _keys       = groupKeys;
            _aggregates = aggregates;
        }
示例#34
0
        internal static TypeUsage ValidateNew(
            TypeUsage instanceType,
            IEnumerable <DbExpression> arguments,
            out DbExpressionList validArguments)
        {
            ArgumentValidation.CheckType(instanceType, nameof(instanceType));
            CollectionType type = (CollectionType)null;

            if (TypeHelpers.TryGetEdmType <CollectionType>(instanceType, out type) && type != null)
            {
                TypeUsage elementType = type.TypeUsage;
                validArguments = ArgumentValidation.CreateExpressionList(arguments, nameof(arguments), true, (Action <DbExpression, int>)((exp, idx) => ArgumentValidation.RequireCompatibleType(exp, elementType, nameof(arguments), idx)));
            }
            else
            {
                List <TypeUsage> expectedTypes = ArgumentValidation.GetStructuralMemberTypes(instanceType);
                int pos = 0;
                validArguments = ArgumentValidation.CreateExpressionList(arguments, nameof(arguments), expectedTypes.Count, (Action <DbExpression, int>)((exp, idx) => ArgumentValidation.RequireCompatibleType(exp, expectedTypes[pos++], nameof(arguments), idx)));
            }
            return(instanceType);
        }
示例#35
0
 internal DbGroupAggregate(TypeUsage resultType, DbExpressionList arguments)
     : base(resultType, arguments)
 {
 }