protected override Expression VisitEntity(DbEntityExpression entity)
        {
            var save = this.includeScope;
            this.includeScope = new ScopedDictionary<MemberInfo,bool>(this.includeScope);
            try
            {
                entity = this.mapping.IncludeMembers(
                    entity,  
                    m => {
                        if (this.includeScope.ContainsKey(m))
                        {
                            return false;
                        }
                        if (this.policy.IsIncluded(m))
                        {
                            this.includeScope.Add(m, true);
                            return true;
                        }
                        return false;
                    });

                return base.VisitEntity(entity);
            }
            finally
            {
                this.includeScope = save;
            }
        }
Esempio n. 2
0
        protected override Expression VisitMemberAccess(MemberExpression m)
        {
            Expression         source = this.Visit(m.Expression);
            DbEntityExpression ex     = source as DbEntityExpression;

            if (ex != null && this.mapping.IsAssociation(ex.Entity, m.Member))
            {
                DbProjectionExpression projection = (DbProjectionExpression)this.Visit(this.mapping.CreateMemberExpression(source, ex.Entity, m.Member));
                if (this.currentFrom != null && this.mapping.IsSingletonAssociation(ex.Entity, m.Member))
                {
                    // convert singleton associations directly to OUTER APPLY
                    projection = projection.AddOuterJoinTest();
                    Expression newFrom = new DbJoinExpression(DbJoinType.OuterApply, this.currentFrom, projection.Select, null);
                    this.currentFrom = newFrom;
                    return(projection.Projector);
                }
                return(projection);
            }
            else
            {
                Expression       result = QueryBinder.BindMember(source, m.Member);
                MemberExpression mex    = result as MemberExpression;
                if (mex != null && mex.Member == m.Member && mex.Expression == m.Expression)
                {
                    return(m);
                }
                return(result);
            }
        }
Esempio n. 3
0
        protected override Expression VisitEntity(DbEntityExpression entity)
        {
            var save = this.includeScope;

            this.includeScope = new ScopedDictionary <MemberInfo, bool>(this.includeScope);
            try
            {
                entity = this.mapping.IncludeMembers(
                    entity,
                    m => {
                    if (this.includeScope.ContainsKey(m))
                    {
                        return(false);
                    }
                    if (this.policy.IsIncluded(m))
                    {
                        this.includeScope.Add(m, true);
                        return(true);
                    }
                    return(false);
                });

                return(base.VisitEntity(entity));
            }
            finally
            {
                this.includeScope = save;
            }
        }
 protected DbEntityExpression UpdateEntity(DbEntityExpression entity, 
     Expression expression)
 {
     if (expression != entity.Expression)
         return new DbEntityExpression(entity.Entity, expression);
     
     return entity;
 }
Esempio n. 5
0
        private Expression BindRelationshipProperty(MemberExpression mex)
        {
            DbEntityExpression ex = mex.Expression as DbEntityExpression;

            if (ex != null && this.mapping.IsAssociation(ex.Entity, mex.Member))
            {
                return(this.mapping.CreateMemberExpression(mex.Expression, ex.Entity, mex.Member));
            }
            return(mex);
        }
Esempio n. 6
0
        protected DbEntityExpression UpdateEntity(DbEntityExpression entity,
                                                  Expression expression)
        {
            if (expression != entity.Expression)
            {
                return(new DbEntityExpression(entity.Entity, expression));
            }

            return(entity);
        }
 protected virtual Expression VisitEntity(DbEntityExpression entity)
 {
     Expression exp = Visit(entity.Expression);
     return UpdateEntity(entity, exp);
 }
 protected virtual bool CompareEntity(DbEntityExpression x, DbEntityExpression y)
 {
     return(x.Entity == y.Entity && Compare(x.Expression, y.Expression));
 }
Esempio n. 9
0
 protected override Expression VisitEntity(DbEntityExpression entity)
 {
     return(this.Visit(entity.Expression));
 }
Esempio n. 10
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));
        }
 protected virtual bool CompareEntity(DbEntityExpression x, DbEntityExpression y)
 {
     return x.Entity == y.Entity && Compare(x.Expression, y.Expression);
 }
Esempio n. 12
0
 /// <summary>
 /// Recreate the type projection with the 
 /// additional members included
 /// </summary>
 public abstract DbEntityExpression IncludeMembers(DbEntityExpression entity, Func<MemberInfo, bool> isIncluded);
Esempio n. 13
0
        protected virtual Expression VisitEntity(DbEntityExpression entity)
        {
            Expression exp = Visit(entity.Expression);

            return(UpdateEntity(entity, exp));
        }