Esempio n. 1
0
 public override void Visit(PropertyOp op, Node n)
 {
     using (new AutoString(this, op)) {
         VisitChildren(n);
         WriteString(".");
         WriteString(op.PropertyInfo.Name);
     }
 }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="userId">user id</param>
        /// <returns>user profile model</returns>
        public ProfileModel GetUserProfileModel(int userId)
        {
            ProfileModel model = UserModel.DbEntityToProfilModel(UserOp.GetUser(userId));

            model.AllProperties = PropertyModel.ToModelList(PropertyOp.Properties);
            model.Properties    = PropertyModel.ToModelList(PropertyOp.GetUserProperties(userId));
            return(model);
        }
Esempio n. 3
0
 public override System.Data.Entity.Core.Query.InternalTrees.Node Visit(
     PropertyOp op,
     System.Data.Entity.Core.Query.InternalTrees.Node n)
 {
     if (n.Child0.Op.OpType != OpType.VarRef)
     {
         return(base.Visit(op, n));
     }
     return(this.TranslateOverGroupAggregateVar(((VarRefOp)n.Child0.Op).Var, op.PropertyInfo));
 }
Esempio n. 4
0
        /// <summary>
        /// If the child is VarRef check if the subtree PropertyOp(VarRef) is reference to a
        /// group aggregate var.
        /// Otherwise do default processing
        /// </summary>
        /// <param name="op"></param>
        /// <param name="n"></param>
        /// <returns></returns>
        public override Node Visit(PropertyOp op, Node n)
        {
            if (n.Child0.Op.OpType != OpType.VarRef)
            {
                return(base.Visit(op, n));
            }
            VarRefOp varRefOp = (VarRefOp)n.Child0.Op;

            return(TranslateOverGroupAggregateVar(varRefOp.Var, op.PropertyInfo));
        }
Esempio n. 5
0
        /// <summary>
        /// updates user profile
        /// </summary>
        /// <param name="profileModel">updated user prifile</param>
        /// <returns>updated profile model</returns>
        public ProfileModel UpdateProfile(ProfileModel profileModel)
        {
            UserOp.UpdateUser(profileModel.GetUserEntity());
            List <Property> pm = PropertyModel.ToEntityList(profileModel.Properties);

            pm = pm.GroupBy(test => test.Name)
                 .Select(grp => grp.First())
                 .ToList();
            profileModel.Properties = PropertyModel.ToModelList(PropertyOp.AddUserProperties(profileModel.Id, pm));
            return(profileModel);
        }
Esempio n. 6
0
        /// <summary>
        /// converts DB entity User to ProfilModel
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public static ProfileModel DbEntityToProfilModel(User user)
        {
            ProfileModel model = new ProfileModel();

            model.Id         = user.Id;
            model.FirstName  = user.FirstName;
            model.LastName   = user.LastName;
            model.Password   = user.PasswordHash;
            model.Properties = new List <PropertyModel>();
            foreach (Property p in PropertyOp.GetUserProperties(user.Id))
            {
                model.Properties.Add(PropertyModel.ToModel(p));
            }
            model.SecretQuestion         = user.SecretQuestion;
            model.StakeholderDescription = user.StakeholderDescription;
            model.Email  = user.Email;
            model.Answer = user.Answer;
            return(model);
        }
Esempio n. 7
0
        /// <summary>
        /// Validates that the nav property agrees with the underlying relationship
        /// </summary>
        /// <param name="op">the Nav PropertyOp</param>
        private static void ValidateNavPropertyOp(PropertyOp op)
        {
            var navProperty = (NavigationProperty)op.PropertyInfo;

            //
            // If the result of the expanded form of the navigation property is not compatible with
            // the declared type of the property, then the navigation property is invalid in the
            // context of this command tree's metadata workspace.
            //
            var resultType = navProperty.ToEndMember.TypeUsage;
            if (TypeSemantics.IsReferenceType(resultType))
            {
                resultType = TypeHelpers.GetElementTypeUsage(resultType);
            }
            if (navProperty.ToEndMember.RelationshipMultiplicity
                == RelationshipMultiplicity.Many)
            {
                resultType = TypeUsage.Create(resultType.EdmType.GetCollectionType());
            }
            if (!TypeSemantics.IsStructurallyEqualOrPromotableTo(resultType, op.Type))
            {
                throw new MetadataException(
                    Strings.EntityClient_IncompatibleNavigationPropertyResult(
                        navProperty.DeclaringType.FullName,
                        navProperty.Name));
            }
        }
 public override void Visit(PropertyOp op, Node n)
 {
     VisitScalarOpDefault(op, n);
     AssertEqualTypes(n.Child0.Op.Type, op.PropertyInfo.DeclaringType);
 }
Esempio n. 9
0
 /// <summary>
 /// Copies a PropertyOp
 /// </summary>
 /// <param name="op">The Op to Copy</param>
 /// <param name="n">The Node that references the Op</param>
 /// <returns>A copy of the original Node that references a copy of the original Op</returns>
 public override Node Visit(PropertyOp op, Node n)
 {
     return(CopyDefault(m_destCmd.CreatePropertyOp(op.PropertyInfo), n));
 }
 /// <summary>
 ///     Visitor pattern method for PropertyOp
 /// </summary>
 /// <param name="op"> The PropertyOp being visited </param>
 /// <param name="n"> The Node that references the Op </param>
 public virtual void Visit(PropertyOp op, Node n)
 {
     VisitScalarOpDefault(op, n);
 }
Esempio n. 11
0
 public override void Visit(PropertyOp op, System.Data.Entity.Core.Query.InternalTrees.Node n)
 {
     this.VisitPropertyOp((Op)op, n, (PropertyRef) new SimplePropertyRef(op.PropertyInfo));
 }
 /// <summary>
 ///     PropertyOp
 ///     If this is a scalar/collection property, then simply get the appropriate
 ///     field out.
 ///     Otherwise, build up a record constructor corresponding to the result
 ///     type - optimize this by only getting those properties that are needed
 ///     If the instance is not a structured type (ie) it is a UDT, then simply return
 /// </summary>
 /// <param name="op"> the PropertyOp </param>
 /// <param name="n"> the corresponding node </param>
 /// <returns> new subtree </returns>
 public override Node Visit(PropertyOp op, Node n)
 {
     return VisitPropertyOp(op, n, new SimplePropertyRef(op.PropertyInfo), throwIfMissing: true);
 }
Esempio n. 13
0
 // <summary>
 // Copies a PropertyOp
 // </summary>
 // <param name="op"> The Op to Copy </param>
 // <param name="n"> The Node that references the Op </param>
 // <returns> A copy of the original Node that references a copy of the original Op </returns>
 public override Node Visit(PropertyOp op, Node n)
 {
     return CopyDefault(m_destCmd.CreatePropertyOp(op.PropertyInfo), n);
 }
Esempio n. 14
0
        // <summary>
        // Rewrite a PropertyOp subtree for a nav property
        // <see cref="RewriteNavigationProperty" /> does the heavy lifting
        // </summary>
        // <param name="op"> the PropertyOp </param>
        // <param name="n"> the current node </param>
        // <returns> the rewritten subtree </returns>
        private Node VisitNavPropertyOp(PropertyOp op, Node n)
        {
            ValidateNavPropertyOp(op);

            //
            // In this special case we visit the parent before the child to avoid TSQL regressions. 
            // In particular, a subquery coming out of the child would need to be attached to the closest rel-op parent
            // and if the parent is already visited that rel op parent would be part of the subtree resulting from the parent.
            // If the parent is not visited it would be a rel op parent higher in the tree (also valid), and leaves less room 
            // for join elimination. 
            // The original out-of-order visitation was put in place to work around a bug that has been fixed.
            //
            var visitChildLater = IsNavigationPropertyOverVarRef(n.Child0);
            if (!visitChildLater)
            {
                VisitScalarOpDefault(op, n);
            }

            // Cache and reuse the rewritten nodes to avoid duplicate joins. 
            // The logic for cache hits is implemented in the NavigationPropertyOpInfo class. Basically two navigation property nodes 
            // are considered equivalent from the cache point of view if they have the same RelOp ancestor (not null), same navigation 
            // property (EdmMember) and the subtrees having them as root are equivalent. For fast retrieval a hash code is computed
            // using the RelOp ancestor's hash code, the navigation property's hash code and the node's computed hash value.

            var nodeInfo = new NavigationPropertyOpInfo(n, FindRelOpAncestor(), m_command);
            Node rewrite;

            if (_navigationPropertyOpRewrites.TryGetValue(nodeInfo, out rewrite))
            {
                return OpCopier.Copy(m_command, rewrite);
            }

            // Seal the nodeInfo instance to ensure the immutability of the fields used to implement NavigationPropertyOpInfo.Equals.
            // The implementation replaces the original node referenced by nodeInfo with a clone. Potential changes to the original  
            // will not affect the result of Equals. This is needed to make the dictionary lookups reliable.
            nodeInfo.Seal();

            rewrite = RewriteNavigationProperty((NavigationProperty) op.PropertyInfo, n.Child0, op.Type);
            rewrite = VisitNode(rewrite);

            _navigationPropertyOpRewrites.Add(nodeInfo, rewrite);

            return rewrite;
        }
Esempio n. 15
0
 public override void Visit(PropertyOp op, Node n)
 {
     VisitScalarOpDefault(op, n);
     AssertEqualTypes(n.Child0.Op.Type, op.PropertyInfo.DeclaringType);
 }
Esempio n. 16
0
        /// <summary>
        /// Rewrite a PropertyOp subtree for a nav property
        /// <see cref="RewriteNavigationProperty"/> does the heavy lifting
        /// </summary>
        /// <param name="op">the PropertyOp</param>
        /// <param name="n">the current node</param>
        /// <returns>the rewritten subtree</returns>
        private Node VisitNavPropertyOp(PropertyOp op, Node n)
        {
            ValidateNavPropertyOp(op);

            //
            // In this special case we visit the parent before the child to avoid TSQL regressions. 
            // In particular, a subquery coming out of the child would need to be attached to the closest rel-op parent
            // and if the parent is already visited that rel op parent would be part of the subtree resulting from the parent.
            // If the parent is not visited it would be a rel op parent higher in the tree (also valid), and leaves less room 
            // for join elimination. 
            // The original out-of-order visitation was put in place to work around a bug that has been fixed.
            //
            var visitChildLater = IsNavigationPropertyOverVarRef(n.Child0);
            if (!visitChildLater)
            {
                VisitScalarOpDefault(op, n);
            }

            var navProperty = (NavigationProperty)op.PropertyInfo;
            var ret = RewriteNavigationProperty(navProperty, n.Child0, op.Type);
            ret = VisitNode(ret);

            return ret;
        }
Esempio n. 17
0
 /// <summary>
 /// Rewrite a PropertyOp subtree.  
 /// 
 /// If the PropertyOp represents a simple property (ie) not a navigation property, we simply call
 /// VisitScalarOpDefault() and return. Otherwise, we call VisitNavPropertyOp and return the result from
 /// that function
 /// 
 /// </summary>
 /// <param name="op">the PropertyOp</param>
 /// <param name="n">the PropertyOp subtree</param>
 /// <returns>the rewritten tree</returns>
 public override Node Visit(PropertyOp op, Node n)
 {
     Node ret;
     if (Helper.IsNavigationProperty(op.PropertyInfo))
     {
         ret = VisitNavPropertyOp(op, n);
     }
     else
     {
         ret = VisitScalarOpDefault(op, n);
     }
     return ret;
 }
 /// <summary>
 /// If the child is VarRef check if the subtree PropertyOp(VarRef) is reference to a 
 /// group aggregate var. 
 /// Otherwise do default processing
 /// </summary>
 /// <param name="op"></param>
 /// <param name="n"></param>
 /// <returns></returns>
 public override Node Visit(PropertyOp op, Node n)
 {
     if (n.Child0.Op.OpType
         != OpType.VarRef)
     {
         return base.Visit(op, n);
     }
     var varRefOp = (VarRefOp)n.Child0.Op;
     return TranslateOverGroupAggregateVar(varRefOp.Var, op.PropertyInfo);
 }
 /// <summary>
 /// PropertyOp handling
 ///
 /// Pushes down the requested properties along with the current
 /// property to the child
 /// </summary>
 /// <param name="op"></param>
 /// <param name="n"></param>
 public override void Visit(PropertyOp op, Node n)
 {
     VisitPropertyOp(op, n, new SimplePropertyRef(op.PropertyInfo));
 }
 /// <summary>
 ///     PropertyOp handling
 /// 
 ///     Pushes down the requested properties along with the current 
 ///     property to the child
 /// </summary>
 /// <param name="op"> </param>
 /// <param name="n"> </param>
 public override void Visit(PropertyOp op, Node n)
 {
     VisitPropertyOp(op, n, new SimplePropertyRef(op.PropertyInfo));
 }