Esempio n. 1
0
        internal override DbExpression AsCqt(DbExpression row, bool skipIsNotNull)
        {
            DbExpression cqt = this.RestrictedMemberSlot.MemberPath.AsCqt(row);

            if (Helper.IsRefType((GlobalItem)this.RestrictedMemberSlot.MemberPath.EdmType))
            {
                cqt = (DbExpression)cqt.Deref();
            }
            if (this.Domain.Count == 1)
            {
                cqt = (DbExpression)cqt.IsOfOnly(TypeUsage.Create(((TypeConstant)this.Domain.Values.Single <Constant>()).EdmType));
            }
            else
            {
                cqt = Helpers.BuildBalancedTreeInPlace <DbExpression>((IList <DbExpression>) this.Domain.Values.Select <Constant, DbExpression>((Func <Constant, DbExpression>)(t => (DbExpression)cqt.IsOfOnly(TypeUsage.Create(((TypeConstant)t).EdmType)))).ToList <DbExpression>(), (Func <DbExpression, DbExpression, DbExpression>)((prev, next) => (DbExpression)prev.Or(next)));
            }
            return(cqt);
        }
Esempio n. 2
0
        private bool TryResolveAsRefPropertyAccess(
            DbExpression valueExpr,
            string name,
            ErrorContext errCtx,
            out DbExpression propertyExpr)
        {
            propertyExpr = (DbExpression)null;
            if (!TypeSemantics.IsReferenceType(valueExpr.ResultType))
            {
                return(false);
            }
            DbExpression valueExpr1 = (DbExpression)valueExpr.Deref();
            TypeUsage    resultType = valueExpr1.ResultType;

            if (this.TryResolveAsPropertyAccess(valueExpr1, name, out propertyExpr))
            {
                return(true);
            }
            string errorMessage = Strings.InvalidDeRefProperty((object)name, (object)resultType.EdmType.FullName, (object)valueExpr.ResultType.EdmType.FullName);

            throw EntitySqlException.Create(errCtx, errorMessage, (Exception)null);
        }
Esempio n. 3
0
        internal override DbExpression AsCqt(DbExpression row, bool skipIsNotNull)
        {
            DbExpression cqt = this.RestrictedMemberSlot.MemberPath.AsCqt(row);

            if (Helper.IsRefType(this.RestrictedMemberSlot.MemberPath.EdmType))
            {
                cqt = cqt.Deref();
            }

            if (this.Domain.Count == 1)
            {
                // Single value
                cqt = cqt.IsOfOnly(TypeUsage.Create(((TypeConstant)this.Domain.Values.Single()).EdmType));
            }
            else
            {
                // Multiple values: build list of var IsOnOnly(t1), var = IsOnOnly(t1), ..., then OR them all.
                List <DbExpression> operands = this.Domain.Values.Select(t => (DbExpression)cqt.IsOfOnly(TypeUsage.Create(((TypeConstant)t).EdmType))).ToList();
                cqt = Helpers.BuildBalancedTreeInPlace(operands, (prev, next) => prev.Or(next));
            }

            return(cqt);
        }
        /// <summary>
        ///     If <paramref name="valueExpr" /> returns a reference, then deref and try resolving <paramref name="name" /> as a property of the dereferenced value.
        /// </summary>
        private bool TryResolveAsRefPropertyAccess(DbExpression valueExpr, string name, ErrorContext errCtx, out DbExpression propertyExpr)
        {
            DebugCheck.NotNull(valueExpr);

            propertyExpr = null;

            if (TypeSemantics.IsReferenceType(valueExpr.ResultType))
            {
                DbExpression derefExpr     = valueExpr.Deref();
                var          derefExprType = derefExpr.ResultType;

                if (TryResolveAsPropertyAccess(derefExpr, name, out propertyExpr))
                {
                    return(true);
                }
                else
                {
                    var message = Strings.InvalidDeRefProperty(name, derefExprType.EdmType.FullName, valueExpr.ResultType.EdmType.FullName);
                    throw EntitySqlException.Create(errCtx, message, null);
                }
            }

            return(false);
        }