bool HasIncludedMembers(EntityExpression entity) { foreach (var mi in entity.Entity.Members) { if (policy.IsIncluded(mi.Member)) { return(true); } } return(false); }
protected override Expression VisitEntity(EntityExpression entity) { var init = entity.Expression as MemberInitExpression; if (init != null) { var save = includeScope; includeScope = new ScopedDictionary <IProperty, bool>(this.includeScope); List <MemberBinding> newBindings = null; foreach (var property in PropertyUnity.GetRelatedProperties(entity.Type)) { PropertyInfo member; if (property is IPropertyLazy && policy.IsIncluded(member = property.Info.ReflectionInfo)) { if (includeScope.ContainsKey(property)) { throw new NotSupportedException(string.Format("Cannot include '{0}.{1}' recursively.", property.Type, property.Name)); } var me = QueryUtility.GetMemberExpression(init, property); if (newBindings == null) { newBindings = new List <MemberBinding>(init.Bindings); } newBindings.Add(Expression.Bind(member, me)); } } if (newBindings != null) { entity = new EntityExpression(entity.Metadata, Expression.MemberInit(init.NewExpression, newBindings)); } includeScope = save; } return(base.VisitEntity(entity)); }