Пример #1
0
        /// <summary>
        /// Removes the object from the model.
        /// </summary>
        public void Remove()
        {
            try
            {
                if (Mapping != null)
                {
                    Mapping.Remove();
                }

                if (_functionElement.ParentNode != null)
                {
                    _functionElement.ParentNode.RemoveChild(_functionElement);

                    if (Removed != null)
                    {
                        Removed(this, new EventArgs());
                    }
                }
            }
            catch (Exception ex)
            {
                try
                {
                    ExceptionTools.AddExceptionData(ex, this);
                }
                catch { }
                throw;
            }
        }
Пример #2
0
 internal void UpdateKeyName(ModelEntityType entityType, ModelMemberProperty memberProperty, string oldName, string newName)
 {
     try
     {
         if (entityType == FromEntitySet.EntityType)
         {
             foreach (XmlElement key in _associationElement.SelectNodes("edm:ReferentialConstraint/edm:Dependent/edm:PropertyRef[@Name=" + XmlHelpers.XPathLiteral(oldName) + "]", NSM))
             {
                 key.SetAttribute("Name", newName);
             }
         }
         else if (entityType == ToEntitySet.EntityType)
         {
             foreach (XmlElement key in _associationElement.SelectNodes("edm:ReferentialConstraint/edm:Principal/edm:PropertyRef[@Name=" + XmlHelpers.XPathLiteral(oldName) + "]", NSM))
             {
                 key.SetAttribute("Name", newName);
             }
         }
         else
         {
             throw new ArgumentException("The entity type " + entityType.Name + " does not participate in the association " + this.Name);
         }
     }
     catch (Exception ex)
     {
         try
         {
             ExceptionTools.AddExceptionData(ex, this);
         }
         catch { }
         throw;
     }
 }
Пример #3
0
 /// <summary>
 /// Adds a new scalar member to the type
 /// </summary>
 /// <param name="name">Member name</param>
 /// <param name="type">Member type. Must be a EDM compatible CLR type.</param>
 /// <param name="nullable">Nullable or non-nullable?</param>
 /// <returns>A ModelMemberProperty object corresponding to the new member.</returns>
 public ModelMemberProperty AddMember(string name, Type type, bool nullable)
 {
     try
     {
         if (!MemberProperties.Where(mp => mp.Name == name).Any() &&
             name != this.Name)
         {
             ModelMemberProperty mp = new ModelMemberProperty(base.ParentFile, this, name, _complexTypeElement);
             mp.Type     = type;
             mp.Nullable = nullable;
             _memberProperties.Add(name, mp);
             mp.NameChanged += new EventHandler <NameChangeArgs>(prop_NameChanged);
             mp.Removed     += new EventHandler(prop_Removed);
             return(mp);
         }
         else
         {
             throw new ArgumentException("A property with the name " + name + " already exist in the type " + this.Name);
         }
     }
     catch (Exception ex)
     {
         try
         {
             ExceptionTools.AddExceptionData(ex, this);
         }
         catch { }
         throw;
     }
 }
Пример #4
0
        /// <summary>
        /// Removes the object from the model.
        /// </summary>
        public void Remove()
        {
            try
            {
                foreach (StoreAssociationSet sas in this.AssociationsFrom.Union(this.AssociationsTo).ToList())
                {
                    sas.Remove();
                }

                foreach (AssociationSetMapping asm in this.AssociationSetMappings.ToList())
                {
                    asm.Remove();
                }

                if (_entitySetElement.ParentNode != null)
                {
                    _entitySetElement.ParentNode.RemoveChild(_entitySetElement);

                    if (Removed != null)
                    {
                        Removed(this, new EventArgs());
                    }
                }
            }
            catch (Exception ex)
            {
                try
                {
                    ExceptionTools.AddExceptionData(ex, this);
                }
                catch { }
                throw;
            }
        }
Пример #5
0
 /// <summary>
 /// Adds a scalar member to this entity type.
 /// </summary>
 /// <param name="name">Name of the new member property.</param>
 /// <param name="type">Type of the new member property.</param>
 /// <param name="nullable">Nullable; true or false.</param>
 /// <param name="ordinal">Ordinal position within the entity type.</param>
 /// <returns>A ModelMemberProperty object.</returns>
 public ModelMemberProperty AddMember(string name, Type type, bool nullable, int ordinal)
 {
     try
     {
         if (!MemberProperties.Where(mp => mp.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase)).Any() &&
             !NavigationProperties.Any(np => np.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase)) &&
             name != this.Name)
         {
             ModelMemberProperty mp = new ModelMemberProperty(base.ParentFile, this, name, ordinal, _entityTypeElement);
             mp.Type     = type;
             mp.Nullable = nullable;
             _memberProperties.Add(name, mp);
             mp.NameChanged += new EventHandler <NameChangeArgs>(prop_NameChanged);
             mp.Removed     += new EventHandler(prop_Removed);
             return(mp);
         }
         else
         {
             throw new ArgumentException("A property with the name " + name + " already exist in the type " + this.Name);
         }
     }
     catch (Exception ex)
     {
         try
         {
             ExceptionTools.AddExceptionData(ex, this);
         }
         catch { }
         throw;
     }
 }
Пример #6
0
        /// <summary>
        /// Removes the object from the model.
        /// </summary>
        public void Remove()
        {
            try
            {
                if (_entityTypeElement.ParentNode != null)
                {
                    if (DiagramShape != null)
                    {
                        DiagramShape.Remove();
                    }

                    _entityTypeElement.ParentNode.RemoveChild(_entityTypeElement);

                    if (Removed != null)
                    {
                        Removed(this, new EventArgs());
                    }
                }
            }
            catch (Exception ex)
            {
                try
                {
                    ExceptionTools.AddExceptionData(ex, this);
                }
                catch { }
                throw;
            }
        }
Пример #7
0
 /// <summary>
 /// Adds a parameter to the function definition.
 /// </summary>
 /// <param name="name">Parameter name</param>
 /// <param name="dataType">Data type</param>
 /// <param name="ordinal">Ordinal position in relation to other parameters. (Zero-based)</param>
 /// <returns>A StoreFunctionParameter object.</returns>
 public StoreFunctionParameter AddParameter(string name, string dataType, int ordinal)
 {
     try
     {
         if (!Parameters.Where(mp => mp.Name == name).Any())
         {
             StoreFunctionParameter mp = new StoreFunctionParameter(base.ParentFile, this, name, ordinal, _functionElement);
             mp.DataType = dataType;
             _parameters.Add(name, mp);
             mp.NameChanged += new EventHandler <NameChangeArgs>(prop_NameChanged);
             mp.Removed     += new EventHandler(prop_Removed);
             return(mp);
         }
         else
         {
             throw new ArgumentException("A parameter with the name " + name + " already exist in the function " + this.Name);
         }
     }
     catch (Exception ex)
     {
         try
         {
             ExceptionTools.AddExceptionData(ex, this);
         }
         catch { }
         throw;
     }
 }
Пример #8
0
 /// <summary>
 /// Adds a navigation property to the entity type.
 /// </summary>
 /// <param name="navigationPropertyName">Name of the navigation property.</param>
 /// <param name="modelAssociationSet">Association set that this navigation property is based on.</param>
 /// <param name="fromRoleName">From-role. Normally the same as the from-role for the associationset, but can be reversed for recursive associations.</param>
 /// <param name="fromRoleName">To-role. Normally the same as the To-role for the associationset, but can be reversed for recursive associations.</param>
 /// <returns>A NavigationProperty object.</returns>
 public NavigationProperty AddNavigationMember(string navigationPropertyName, ModelAssociationSet modelAssociationSet, string fromRoleName, string toRoleName)
 {
     try
     {
         if (!NavigationProperties.Any(np => np.Name.Equals(navigationPropertyName)) &&
             !MemberProperties.Any(mp => mp.Name.Equals(navigationPropertyName)) &&
             navigationPropertyName != this.Name)
         {
             NavigationProperty navigationProperty = new NavigationProperty(ParentFile, this, navigationPropertyName, modelAssociationSet, _entityTypeElement, fromRoleName, toRoleName);
             _navigationProperties.Add(navigationProperty.Name, navigationProperty);
             navigationProperty.NameChanged += new EventHandler <NameChangeArgs>(navprop_NameChanged);
             navigationProperty.Removed     += new EventHandler(navprop_Removed);
             return(navigationProperty);
         }
         else
         {
             throw new ArgumentException("A property named " + navigationPropertyName + " already exist in the type " + this.Name);
         }
     }
     catch (Exception ex)
     {
         try
         {
             ExceptionTools.AddExceptionData(ex, this);
         }
         catch { }
         throw;
     }
 }
Пример #9
0
        /// <summary>
        /// Removes the object from the model.
        /// </summary>
        public void Remove()
        {
            try
            {
                NavigationProperty navPropFrom = NavigationPropertyFrom;
                NavigationProperty navPropTo   = NavigationPropertyTo;
                try
                {
                    if (navPropFrom != null)
                    {
                        navPropFrom.Remove();
                    }
                }
                catch { }
                try
                {
                    if (navPropTo != null)
                    {
                        navPropTo.Remove();
                    }
                }
                catch { }

                if (this.AssociationSetMapping != null)
                {
                    this.AssociationSetMapping.Remove();
                }

                if (_associationElement.ParentNode != null)
                {
                    _associationElement.ParentNode.RemoveChild(_associationElement);
                    if (_associationSetElement.ParentNode != null)
                    {
                        _associationSetElement.ParentNode.RemoveChild(_associationSetElement);
                    }

                    if (Removed != null)
                    {
                        Removed(this, new EventArgs());
                    }
                }
            }
            catch (Exception ex)
            {
                try
                {
                    ExceptionTools.AddExceptionData(ex, this);
                }
                catch { }
                throw;
            }
        }
        /// <summary>
        /// Removes the object from the model.
        /// </summary>
        public void Remove()
        {
            try
            {
                if (FromEntitySet != null)
                {
                    foreach (AssociationSetMapping asm in FromEntitySet.AssociationSetMappings.ToList())
                    {
                        if (asm != null)
                        {
                            asm.Remove();
                        }
                    }
                }

                if (ToEntitySet != null)
                {
                    foreach (AssociationSetMapping asm in ToEntitySet.AssociationSetMappings.ToList())
                    {
                        if (asm != null)
                        {
                            asm.Remove();
                        }
                    }
                }

                if (_associationElement != null && _associationElement.ParentNode != null)
                {
                    _associationElement.ParentNode.RemoveChild(_associationElement);
                    if (_associationSetElement.ParentNode != null)
                    {
                        _associationSetElement.ParentNode.RemoveChild(_associationSetElement);
                    }

                    if (Removed != null)
                    {
                        Removed(this, new EventArgs());
                    }
                }
            }
            catch (Exception ex)
            {
                try
                {
                    ExceptionTools.AddExceptionData(ex, this);
                }
                catch { }
                throw;
            }
        }
Пример #11
0
 /// <summary>
 /// True if the specified entity type is a parent somewhere in the inheritance chain for this entity type.
 /// </summary>
 /// <param name="entityType">Entity type to look for in the inheritance chain.</param>
 /// <returns>True if found, false if not.</returns>
 public bool IsSubtypeOf(ModelEntityType entityType)
 {
     try
     {
         return(BaseTypes.Any(t => t == entityType));
     }
     catch (Exception ex)
     {
         try
         {
             ExceptionTools.AddExceptionData(ex, this);
         }
         catch { }
         throw;
     }
 }
Пример #12
0
 /// <summary>
 /// True if the specified entity type inherits from this entity type.
 /// </summary>
 /// <param name="entityType">Entity type to look for in the subtypes of this entity.</param>
 /// <returns>True if found, false if not.</returns>
 public bool InheritsFrom(ModelEntityType entityType)
 {
     try
     {
         return(SubTypes.Any(t => t == entityType));
     }
     catch (Exception ex)
     {
         try
         {
             ExceptionTools.AddExceptionData(ex, this);
         }
         catch { }
         throw;
     }
 }
Пример #13
0
        /// <summary>
        /// Removes a key pair from the association
        /// </summary>
        /// <param name="key">A tuple containing the dependent and principal key member to remove</param>
        public void RemoveKey(Tuple <ModelMemberProperty, ModelMemberProperty> key)
        {
            try
            {
                if (_keys.Contains(key))
                {
                    _keys.Remove(key);
                }

                XmlElement fromKeyElement = (XmlElement)_associationElement.SelectSingleNode("edm:ReferentialConstraint/edm:Dependent/edm:PropertyRef[@Name=" + XmlHelpers.XPathLiteral(key.Item1.Name) + "]", NSM);
                if (fromKeyElement != null)
                {
                    if (fromKeyElement.ParentNode != null)
                    {
                        if (fromKeyElement.ParentNode != null)
                        {
                            fromKeyElement.ParentNode.RemoveChild(fromKeyElement);
                        }
                    }
                }

                XmlElement toKeyElement = (XmlElement)_associationElement.SelectSingleNode("edm:ReferentialConstraint/edm:Principal/edm:PropertyRef", NSM);
                if (toKeyElement != null)
                {
                    if (toKeyElement.ParentNode != null)
                    {
                        if (toKeyElement.ParentNode != null)
                        {
                            toKeyElement.ParentNode.RemoveChild(toKeyElement);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                try
                {
                    ExceptionTools.AddExceptionData(ex, this);
                }
                catch { }
                throw;
            }
        }
Пример #14
0
 /// <summary>
 /// Removes a key pair based on the dependent key member
 /// </summary>
 /// <param name="modelMemberProperty">Dependent key member</param>
 public void RemoveKeyFrom(ModelMemberProperty modelMemberProperty)
 {
     try
     {
         foreach (Tuple <ModelMemberProperty, ModelMemberProperty> key in Keys.Where(k => k.Item1 == modelMemberProperty))
         {
             RemoveKey(key);
         }
     }
     catch (Exception ex)
     {
         try
         {
             ExceptionTools.AddExceptionData(ex, this);
         }
         catch { }
         throw;
     }
 }
 internal bool IsInheritanceConstraint()
 {
     try
     {
         var q =
             from esm in this.FromEntitySet.EntitySetMappings
             join esm2 in this.ToEntitySet.EntitySetMappings on esm equals esm2
             where esm.EntityTypeFor(this.FromEntitySet) != esm.EntityTypeFor(this.ToEntitySet)
             select esm;
         return(q.Any());
     }
     catch (Exception ex)
     {
         try
         {
             ExceptionTools.AddExceptionData(ex, this);
         }
         catch { }
         throw;
     }
 }
Пример #16
0
 /// <summary>
 /// Retrieves a scalar member in this entity type, or creates it if not found
 /// </summary>
 /// <param name="name">Name of the member property.</param>
 /// <param name="type">Type of the new member property.</param>
 /// <param name="nullable">Nullable; true or false.</param>
 /// <param name="ordinal">Ordinal position within the entity type.</param>
 /// <returns>A ModelMemberProperty object.</returns>
 public ModelMemberProperty GetOrCreateMember(string name, Type type, bool nullable, int ordinal)
 {
     try
     {
         ModelMemberProperty modelMemberProperty = MemberProperties.FirstOrDefault(mp => mp.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase));
         if (modelMemberProperty == null)
         {
             modelMemberProperty = AddMember(name, type, nullable, ordinal);
         }
         return(modelMemberProperty);
     }
     catch (Exception ex)
     {
         try
         {
             ExceptionTools.AddExceptionData(ex, this);
         }
         catch { }
         throw;
     }
 }
Пример #17
0
 /// <summary>
 /// Retrieves an existing scalar member to the entity type, or creates a new one if it doesn't exist.
 /// </summary>
 /// <param name="name">Scalar member name.</param>
 /// <param name="dataType">Data type name</param>
 /// <param name="ordinal">Ordinal position of the member within the type. (zero-based)</param>
 /// <returns>A StoreMemberProperty object.</returns>
 public StoreMemberProperty GetOrCreateMember(string name, string dataType, int ordinal)
 {
     try
     {
         StoreMemberProperty storeMemberProperty = MemberProperties.FirstOrDefault(mp => mp.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase));
         if (storeMemberProperty == null)
         {
             storeMemberProperty = AddMember(name, dataType, ordinal);
         }
         return(storeMemberProperty);
     }
     catch (Exception ex)
     {
         try
         {
             ExceptionTools.AddExceptionData(ex, this);
         }
         catch { }
         throw;
     }
 }
Пример #18
0
        /// <summary>
        /// Removes all parameters.
        /// </summary>
        public void ClearParameters()
        {
            try
            {
                foreach (XmlElement parameter in _functionElement.SelectNodes("ssdl:Parameter", NSM))
                {
                    _functionElement.RemoveChild(parameter);
                }

                _parameterElements = null;
                _parameters.Clear();
                _parametersEnumerated = false;
            }
            catch (Exception ex)
            {
                try
                {
                    ExceptionTools.AddExceptionData(ex, this);
                }
                catch { }
                throw;
            }
        }
Пример #19
0
        /// <summary>
        /// Removes the object from the model.
        /// </summary>
        public void Remove()
        {
            try
            {
                if (_complexTypeElement.ParentNode != null)
                {
                    _complexTypeElement.ParentNode.RemoveChild(_complexTypeElement);

                    if (Removed != null)
                    {
                        Removed(this, new EventArgs());
                    }
                }
            }
            catch (Exception ex)
            {
                try
                {
                    ExceptionTools.AddExceptionData(ex, this);
                }
                catch { }
                throw;
            }
        }
Пример #20
0
        private void EnumerateKeys()
        {
            try
            {
                //get hold of key propertyrefs
                XmlNodeList fromKeys = _associationElement.SelectNodes("edm:ReferentialConstraint/edm:Dependent/edm:PropertyRef", NSM);
                XmlNodeList toKeys   = _associationElement.SelectNodes("edm:ReferentialConstraint/edm:Principal/edm:PropertyRef", NSM);

                //number of keys?
                int keyCount = Math.Max(fromKeys.Count, toKeys.Count);
                int keyNo    = 0;
                while (keyNo < keyCount)
                {
                    //get the from entity type member
                    ModelMemberProperty fromKey = null;
                    if (fromKeys.Count > keyNo)
                    {
                        XmlElement fromElement = (XmlElement)fromKeys[keyNo];
                        if (fromElement != null)
                        {
                            string fromName = fromElement.GetAttribute("Name");
                            fromKey = FromEntitySet.EntityType.MemberProperties.FirstOrDefault(mp => mp.Name == fromName);
                            if (fromKey == null && FromEntitySet.EntityType.HasSubTypes)
                            {
                                //check if it is a subtype member
                                fromKey = FromEntitySet.EntityType.SubTypes.SelectMany(t => t.MemberProperties).FirstOrDefault(mp => mp.Name == fromName);
                            }
                        }
                    }

                    //get the to entity type member
                    ModelMemberProperty toKey = null;
                    if (toKeys.Count > keyNo)
                    {
                        XmlElement toElement = (XmlElement)toKeys[keyNo];
                        if (toElement != null)
                        {
                            string toName = toElement.GetAttribute("Name");
                            toKey = ToEntitySet.EntityType.MemberProperties.FirstOrDefault(mp => mp.Name == toName);
                            if (toKey == null && ToEntitySet.EntityType.HasSubTypes)
                            {
                                //check if it is a subtype member
                                toKey = ToEntitySet.EntityType.SubTypes.SelectMany(t => t.MemberProperties).FirstOrDefault(mp => mp.Name == toName);
                            }
                        }
                    }

                    Tuple <ModelMemberProperty, ModelMemberProperty> key = null;
                    if (!_keys.Any(k => k.Item1.Equals(fromKey) && k.Item2.Equals(toKey)))
                    {
                        key = new Tuple <ModelMemberProperty, ModelMemberProperty>(fromKey, toKey);
                        _keys.Add(key);
                    }
                    else
                    {
                        key = _keys.FirstOrDefault(k => k.Item1.Equals(fromKey) && k.Item2.Equals(toKey));
                    }

                    if (fromKey != null)
                    {
                        fromKey.Removed += new EventHandler(fromKey_Removed);
                    }
                    if (toKey != null)
                    {
                        toKey.Removed += new EventHandler(toKey_Removed);
                    }

                    keyNo++;
                }

                _keysEnumerated = true;
            }
            catch (Exception ex)
            {
                try
                {
                    ExceptionTools.AddExceptionData(ex, this);
                }
                catch { }
                throw;
            }
        }
        private void EnumerateKeys()
        {
            try
            {
                if (_associationElement == null)
                {
                    throw new InvalidOperationException("The association set doesn't have a corresponding association.");
                }

                //get hold of key propertyrefs
                XmlNodeList fromKeys = _associationElement.SelectNodes("ssdl:ReferentialConstraint/ssdl:Dependent/ssdl:PropertyRef", NSM);
                XmlNodeList toKeys   = _associationElement.SelectNodes("ssdl:ReferentialConstraint/ssdl:Principal/ssdl:PropertyRef", NSM);

                //number of keys?
                int keyCount = Math.Max(fromKeys.Count, toKeys.Count);
                int keyNo    = 0;
                while (keyNo < keyCount)
                {
                    //get the from entity type member
                    StoreMemberProperty fromKey = null;
                    if (fromKeys.Count > keyNo)
                    {
                        string fromName = ((XmlElement)fromKeys[keyNo]).GetAttribute("Name");
                        fromKey = FromEntitySet.EntityType.MemberProperties.FirstOrDefault(mp => mp.Name.Equals(fromName, StringComparison.InvariantCultureIgnoreCase));
                    }

                    //get the to entity type member
                    StoreMemberProperty toKey = null;
                    if (toKeys.Count > keyNo)
                    {
                        string toName = ((XmlElement)toKeys[keyNo]).GetAttribute("Name");
                        toKey = ToEntitySet.EntityType.MemberProperties.FirstOrDefault(mp => mp.Name.Equals(toName, StringComparison.InvariantCultureIgnoreCase));
                    }

                    Tuple <StoreMemberProperty, StoreMemberProperty> key = null;
                    if (!_keys.Any(k => k.Item1.Equals(fromKey) && k.Item2.Equals(toKey)))
                    {
                        key = new Tuple <StoreMemberProperty, StoreMemberProperty>(fromKey, toKey);
                        _keys.Add(key);
                    }
                    else
                    {
                        key = _keys.FirstOrDefault(k => k.Item1.Equals(fromKey) && k.Item2.Equals(toKey));
                    }

                    if (fromKey != null)
                    {
                        fromKey.Removed += new EventHandler(fromKey_Removed);
                    }
                    if (toKey != null)
                    {
                        toKey.Removed += new EventHandler(toKey_Removed);
                    }

                    keyNo++;
                }

                _keysEnumerated = true;
            }
            catch (Exception ex)
            {
                try
                {
                    ExceptionTools.AddExceptionData(ex, this);
                }
                catch { }
                throw;
            }
        }