Exemple #1
0
        protected override Expression VisitEntity(DbEntityExpression entity)
        {
            var save = this.includeScope;

            this.includeScope = new ScopedDictionary <MemberInfo, bool>(this.includeScope);

            try
            {
                if (this.mapper.HasIncludedMembers(entity))
                {
                    entity = this.mapper.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);
        }
        internal override bool HasIncludedMembers(DbEntityExpression entity)
        {
            var policy = this.translator.Police.Policy;

            foreach (var mi in this.mapping.GetMappedMembers(entity.Entity))
            {
                if (policy.IsIncluded(mi))
                {
                    return(true);
                }
            }

            return(false);
        }
        internal override DbEntityExpression IncludeMembers(DbEntityExpression entity, Func <MemberInfo, bool> fnIsIncluded)
        {
            var assignments = this.GetAssignments(entity.Expression).ToDictionary(ma => ma.Member.Name);
            var anyAdded    = false;

            foreach (var mi in this.mapping.GetMappedMembers(entity.Entity))
            {
                var okayToInclude = !assignments.TryGetValue(mi.Name, out EntityAssignment ea) || IsNullRelationshipAssignment(entity.Entity, ea);

                if (okayToInclude && fnIsIncluded(mi))
                {
                    ea = new EntityAssignment(mi, this.GetMemberExpression(entity.Expression, entity.Entity, mi));
                    assignments[mi.Name] = ea;
                    anyAdded             = true;
                }
            }

            if (anyAdded)
            {
                return(new DbEntityExpression(entity.Entity, this.BuildEntityExpression(entity.Entity, assignments.Values.ToList())));
            }

            return(entity);
        }
 protected virtual bool CompareEntity(DbEntityExpression x, DbEntityExpression y)
 {
     return(x.Entity == y.Entity && this.Compare(x.Expression, y.Expression));
 }
 protected virtual Expression VisitEntity(DbEntityExpression entity)
 {
     return(this.UpdateEntity(entity, this.Visit(entity.Expression)));
 }
 protected override Expression VisitEntity(DbEntityExpression entity)
 {
     return(this.Visit(entity.Expression));
 }
 internal abstract bool HasIncludedMembers(DbEntityExpression entity);
 internal abstract DbEntityExpression IncludeMembers(DbEntityExpression entity, Func <MemberInfo, bool> fnIsIncluded);
 protected virtual Expression VisitEntity(DbEntityExpression entity)
 {
     this.Visit(entity.Expression); return(entity);
 }