protected override Expression VisitEntity(EntityExpression 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 EntityExpression UpdateEntity(EntityExpression entity, Expression expression) { if (expression != entity.Expression) { return new EntityExpression(entity.Entity, expression); } return entity; }
protected virtual Expression VisitEntity(EntityExpression entity) { var exp = this.Visit(entity.Expression); return this.UpdateEntity(entity, exp); }
public override EntityExpression IncludeMembers(EntityExpression entity, Func<MemberInfo, bool> fnIsIncluded) { var assignments = this.GetAssignments(entity.Expression).ToDictionary(ma => ma.Member.Name); bool anyAdded = false; foreach (var mi in this.mapping.GetMappedMembers(entity.Entity)) { EntityAssignment ea; bool okayToInclude = !assignments.TryGetValue(mi.Name, out 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 EntityExpression(entity.Entity, this.BuildEntityExpression(entity.Entity, assignments.Values.ToList())); } return entity; }
public override bool HasIncludedMembers(EntityExpression entity) { var policy = this.translator.Police.Policy; foreach (var mi in this.mapping.GetMappedMembers(entity.Entity)) { if (policy.IsIncluded(mi)) return true; } return false; }
protected virtual bool CompareEntity(EntityExpression x, EntityExpression y) { return x.Entity == y.Entity && this.Compare(x.Expression, y.Expression); }
/// <summary> /// Recreate the type projection with the additional members included /// </summary> /// <param name="entity"></param> /// <param name="fnIsIncluded"></param> /// <returns></returns> public abstract EntityExpression IncludeMembers(EntityExpression entity, Func<MemberInfo, bool> fnIsIncluded);
/// <summary> /// </summary> /// <returns></returns> public abstract bool HasIncludedMembers(EntityExpression entity);
protected virtual Expression VisitEntity(EntityExpression entity) { this.Visit(entity.Expression); return entity; }