Exemple #1
0
        protected override Expression VisitUnary(UnaryExpression node)
        {
#if (DEBUGPRINT)
            System.Diagnostics.Debug.Print("VisitUnary: {0}", node);
#endif

            var expression = base.VisitUnary(node) as UnaryExpression;

            DbExpression operandExpression = GetDbExpressionForExpression(expression.Operand);

            switch (expression.NodeType)
            {
            case ExpressionType.Not:
                MapExpressionToDbExpression(expression, operandExpression.Not());
                break;

            case ExpressionType.Convert:
                MapExpressionToDbExpression(expression, operandExpression.CastTo(TypeUsageForPrimitiveType(expression.Operand.Type)));
                break;

            default:
                throw new NotImplementedException(string.Format("Unhandled NodeType of {0} in LambdaToDbExpressionVisitor.VisitUnary", expression.NodeType));
            }

            return(expression);
        }
Exemple #2
0
        private DbExpression GenerateScalarPropertyMappingView(EdmProperty edmProperty, EdmProperty columnProperty, DbExpression row)
        {
            DbExpression accessorExpr = GenerateColumnRef(row, columnProperty);

            if (!TypeSemantics.IsEqual(accessorExpr.ResultType, edmProperty.TypeUsage))
            {
                accessorExpr = accessorExpr.CastTo(edmProperty.TypeUsage);
            }
            return(accessorExpr);
        }
        internal override DbExpression AsCqt(DbExpression row, MemberPath outputMember)
        {
            DbExpression dbExpression = this.m_memberPath.AsCqt(row);
            TypeUsage    outputMemberTypeUsage;

            if (this.NeedToCastCqlValue(outputMember, out outputMemberTypeUsage))
            {
                dbExpression = (DbExpression)dbExpression.CastTo(outputMemberTypeUsage);
            }
            return(dbExpression);
        }
        internal override DbExpression AsCqt(DbExpression row, MemberPath outputMember)
        {
            DbExpression cqt = m_memberPath.AsCqt(row);

            TypeUsage outputMemberTypeUsage;

            if (NeedToCastCqlValue(outputMember, out outputMemberTypeUsage))
            {
                cqt = cqt.CastTo(outputMemberTypeUsage);
            }

            return(cqt);
        }
Exemple #5
0
        private static DbExpression GenerateScalarPropertyMappingView(
            EdmProperty edmProperty,
            EdmProperty columnProperty,
            DbExpression row)
        {
            DbExpression columnRef = FunctionImportMappingComposable.GenerateColumnRef(row, columnProperty);

            if (!TypeSemantics.IsEqual(columnRef.ResultType, edmProperty.TypeUsage))
            {
                columnRef = (DbExpression)columnRef.CastTo(edmProperty.TypeUsage);
            }
            return(columnRef);
        }
        // creates a CQT cast expression given the source and target CLR type
        private DbExpression CreateCastExpression(DbExpression source, Type toClrType, Type fromClrType)
        {
            // see if the source can be normalized as a set
            var setSource = NormalizeSetSource(source);
            if (!ReferenceEquals(source, setSource))
            {
                // if the resulting cast is a no-op (no either kind is supported
                // for set sources), yield the source
                if (null == GetCastTargetType(setSource.ResultType, toClrType, fromClrType, true))
                {
                    return source;
                }
            }

            // try to find the appropriate target target for the cast
            var toType = GetCastTargetType(source.ResultType, toClrType, fromClrType, true);
            if (null == toType)
            {
                // null indicates a no-op cast (from the perspective of the model)
                return source;
            }

            return source.CastTo(toType);
        }
 // Cast expression to align types between CQT and eLINQ
 private DbExpression AlignTypes(DbExpression cqt, Type toClrType)
 {
     Type fromClrType = null; // not used in this code path
     var toType = GetCastTargetType(cqt.ResultType, toClrType, fromClrType, false);
     if (null != toType)
     {
         return cqt.CastTo(toType);
     }
     else
     {
         return cqt;
     }
 }