Exemple #1
0
        protected virtual Expression VisitOuterJoined(DbOuterJoinedExpression outer)
        {
            Expression test       = Visit(outer.Test);
            Expression expression = Visit(outer.Expression);

            return(UpdateOuterJoined(outer, test, expression));
        }
Exemple #2
0
        protected DbOuterJoinedExpression UpdateOuterJoined(DbOuterJoinedExpression outer,
                                                            Expression test, Expression expression)
        {
            if (test != outer.Test || expression != outer.Expression)
            {
                return(new DbOuterJoinedExpression(test, expression));
            }

            return(outer);
        }
 public static DbProjectionExpression AddOuterJoinTest(this DbProjectionExpression proj)
 {
     string colName = proj.Select.Columns.GetAvailableColumnName("Test");
     DbSelectExpression newSource = proj.Select.AddColumn(new DbColumnDeclaration(colName, Expression.Constant(1, typeof(int?))));
     Expression newProjector =
         new DbOuterJoinedExpression(
             new DbColumnExpression(typeof(int?), null, newSource.Alias, colName),
             proj.Projector
             );
     return new DbProjectionExpression(newSource, newProjector, proj.Aggregator);
 }
        public static DbProjectionExpression AddOuterJoinTest(this DbProjectionExpression proj)
        {
            string             colName      = proj.Select.Columns.GetAvailableColumnName("Test");
            DbSelectExpression newSource    = proj.Select.AddColumn(new DbColumnDeclaration(colName, Expression.Constant(1, typeof(int?))));
            Expression         newProjector =
                new DbOuterJoinedExpression(
                    new DbColumnExpression(typeof(int?), null, newSource.Alias, colName),
                    proj.Projector
                    );

            return(new DbProjectionExpression(newSource, newProjector, proj.Aggregator));
        }
Exemple #5
0
        protected override Expression VisitOuterJoined(DbOuterJoinedExpression outer)
        {
            Expression          expr   = this.Visit(outer.Expression);
            DbColumnExpression  column = (DbColumnExpression)outer.Test;
            ParameterExpression reader;
            int iOrdinal;

            if (this.scope.TryGetValue(column, out reader, out iOrdinal))
            {
                return(Expression.Condition(
                           Expression.Call(reader, "IsDbNull", null, Expression.Constant(iOrdinal)),
                           Expression.Constant(outer.Type.CreateInstance(), outer.Type),
                           expr
                           ));
            }
            return(expr);
        }
 protected DbOuterJoinedExpression UpdateOuterJoined(DbOuterJoinedExpression outer, 
     Expression test, Expression expression)
 {
     if (test != outer.Test || expression != outer.Expression)
         return new DbOuterJoinedExpression(test, expression);
     
     return outer;
 }
        protected virtual Expression VisitOuterJoined(DbOuterJoinedExpression outer)
        {
            Expression test = Visit(outer.Test);
            Expression expression = Visit(outer.Expression);

            return UpdateOuterJoined(outer, test, expression);
        }
Exemple #8
0
        internal static Expression BindMember(Expression source, MemberInfo member)
        {
            switch (source.NodeType)
            {
            case (ExpressionType)DbExpressionType.Entity:
                DbEntityExpression ex = (DbEntityExpression)source;
                var result            = BindMember(ex.Expression, member);
                MemberExpression mex  = result as MemberExpression;
                if (mex != null && mex.Expression == ex.Expression && mex.Member == member)
                {
                    return(Expression.MakeMemberAccess(source, member));
                }
                return(result);

            case ExpressionType.Convert:
                UnaryExpression ux = (UnaryExpression)source;
                return(BindMember(ux.Operand, member));

            case ExpressionType.MemberInit:
                MemberInitExpression min = (MemberInitExpression)source;
                for (int i = 0, n = min.Bindings.Count; i < n; i++)
                {
                    MemberAssignment assign = min.Bindings[i] as MemberAssignment;
                    if (assign != null && MembersMatch(assign.Member, member))
                    {
                        return(assign.Expression);
                    }
                }
                break;

            case ExpressionType.New:
                NewExpression nex = (NewExpression)source;
                if (nex.Members != null)
                {
                    for (int i = 0, n = nex.Members.Count; i < n; i++)
                    {
                        if (MembersMatch(nex.Members[i], member))
                        {
                            return(nex.Arguments[i]);
                        }
                    }
                }
                else if (nex.Type.IsGenericType && nex.Type.GetGenericTypeDefinition() == typeof(Grouping <,>))
                {
                    if (member.Name == "Key")
                    {
                        return(nex.Arguments[0]);
                    }
                }
                break;

            case (ExpressionType)DbExpressionType.Projection:
                // member access on a projection turns into a new projection w/ member access applied
                DbProjectionExpression proj         = (DbProjectionExpression)source;
                Expression             newProjector = BindMember(proj.Projector, member);
                return(new DbProjectionExpression(proj.Select, newProjector));

            case (ExpressionType)DbExpressionType.OuterJoined:
                DbOuterJoinedExpression oj = (DbOuterJoinedExpression)source;
                Expression em = BindMember(oj.Expression, member);
                if (em is DbColumnExpression)
                {
                    return(em);
                }
                return(new DbOuterJoinedExpression(oj.Test, em));

            case ExpressionType.Conditional:
                ConditionalExpression cex = (ConditionalExpression)source;
                return(Expression.Condition(cex.Test, BindMember(cex.IfTrue, member), BindMember(cex.IfFalse, member)));

            case ExpressionType.Constant:
                ConstantExpression con = (ConstantExpression)source;
                Type memberType        = TypeHelper.GetMemberType(member);
                if (con.Value == null)
                {
                    return(Expression.Constant(GetDefault(memberType), memberType));
                }
                else
                {
                    return(Expression.Constant(GetValue(con.Value, member), memberType));
                }
            }
            return(Expression.MakeMemberAccess(source, member));
        }