Exemplo n.º 1
0
        private static ResolvedJoinInfo CreateResolvedJoinInfo(
            SqlEntityExpression originatingEntity, MetaAssociation metaAssociation, IResolvedTableInfo joinedTableInfo)
        {
            var leftColumn = ResolveMember(originatingEntity, metaAssociation.ThisKey);

            // If needed, implement by using compounds (NewExpressions with named arguments, see NamedExpression.CreateNewExpressionWithNamedArguments.)
            if (metaAssociation.OtherKey.Count > 1)
            {
                throw new NotSupportedException(
                          string.Format(
                              "Associations with more than one column are currently not supported. ({0}.{1})",
                              originatingEntity.Type,
                              metaAssociation.OtherMember.Name));
            }

            var otherKey    = metaAssociation.OtherKey[0];
            var rightColumn = new SqlColumnDefinitionExpression(
                otherKey.Type,
                joinedTableInfo.TableAlias,
                otherKey.MappedName,
                otherKey.IsPrimaryKey);

            var joinCondition = ConversionUtility.MakeBinaryWithOperandConversion(ExpressionType.Equal, leftColumn, rightColumn, false, null);

            return(new ResolvedJoinInfo(joinedTableInfo, joinCondition));
        }
Exemplo n.º 2
0
        public Expression Transform(MethodCallExpression methodCallExpression)
        {
            ArgumentUtility.CheckNotNull("methodCallExpression", methodCallExpression);

            if (methodCallExpression.Arguments.Count == 1)
            {
                MethodCallTransformerUtility.CheckInstanceMethod(methodCallExpression);
                return(ConversionUtility.MakeBinaryWithOperandConversion(
                           ExpressionType.Equal, methodCallExpression.Object, methodCallExpression.Arguments[0], false, null));
            }
            else if (methodCallExpression.Arguments.Count == 2)
            {
                MethodCallTransformerUtility.CheckStaticMethod(methodCallExpression);
                return(ConversionUtility.MakeBinaryWithOperandConversion(
                           ExpressionType.Equal, methodCallExpression.Arguments[0], methodCallExpression.Arguments[1], false, null));
            }

            var message = string.Format(
                "{0} function with {1} arguments is not supported. Expression: '{2}'",
                methodCallExpression.Method.Name,
                methodCallExpression.Arguments.Count,
                methodCallExpression);

            throw new NotSupportedException(message);
        }
Exemplo n.º 3
0
        public void MakeBinaryWithOperandConversion_Coalesce()
        {
            var left  = Expression.Constant(0, typeof(int?));
            var right = Expression.Constant(0, typeof(int));

            var result = ConversionUtility.MakeBinaryWithOperandConversion(ExpressionType.Coalesce, left, right, false, null);

            var expectedExpression = BinaryExpression.Coalesce(left, right);

            SqlExpressionTreeComparer.CheckAreEqualTrees(expectedExpression, result);
        }
Exemplo n.º 4
0
        public void MakeBinaryWithOperandConversion_BothOperands_LiftedToObject()
        {
            var left  = Expression.Constant(null, typeof(string));
            var right = Expression.Constant(null, typeof(Cook));

            var result = ConversionUtility.MakeBinaryWithOperandConversion(ExpressionType.Equal, left, right, false, null);

            var expectedExpression = BinaryExpression.Equal(Expression.Convert(left, typeof(object)), Expression.Convert(right, typeof(object)));

            SqlExpressionTreeComparer.CheckAreEqualTrees(expectedExpression, result);
        }
Exemplo n.º 5
0
        public void MakeBinaryWithOperandConversion_RightOperand_LiftedToTypeOfLeft()
        {
            var left  = Expression.Constant(0, typeof(int?));
            var right = Expression.Constant(0, typeof(int));

            var result = ConversionUtility.MakeBinaryWithOperandConversion(ExpressionType.Equal, left, right, false, null);

            var expectedExpression = BinaryExpression.Equal(left, Expression.Convert(right, typeof(int?)));

            SqlExpressionTreeComparer.CheckAreEqualTrees(expectedExpression, result);
        }
        private ResolvedJoinInfo CreateResolvedJoinInfo(
            SqlEntityExpression originatingEntity,
            string leftColumnName,
            Type leftColumnType,
            bool leftColumnIsPrimaryKey,
            IResolvedTableInfo joinedTableInfo,
            string rightColumnName,
            Type rightColumnType,
            bool rightColumnIsPrimaryKey)
        {
            var leftColumn  = originatingEntity.GetColumn(leftColumnType, leftColumnName, leftColumnIsPrimaryKey);
            var rightColumn = CreateColumn(rightColumnType, joinedTableInfo.TableAlias, rightColumnName, rightColumnIsPrimaryKey);

            return(new ResolvedJoinInfo(
                       joinedTableInfo, ConversionUtility.MakeBinaryWithOperandConversion(ExpressionType.Equal, leftColumn, rightColumn, false, null)));
        }
Exemplo n.º 7
0
        public BinaryExpression ResolvePotentialEntityComparison(BinaryExpression binaryExpression)
        {
            ArgumentUtility.CheckNotNull("binaryExpression", binaryExpression);

            var newLeft  = ResolvePotentialEntity(binaryExpression.Left);
            var newRight = ResolvePotentialEntity(binaryExpression.Right);

            if (newLeft != binaryExpression.Left || newRight != binaryExpression.Right)
            {
                // Note: Method is stripped because when an entity is reduced to its identity, the method can no longer work.
                return(ConversionUtility.MakeBinaryWithOperandConversion(
                           binaryExpression.NodeType,
                           newLeft,
                           newRight,
                           false,
                           null));
            }

            return(binaryExpression);
        }