예제 #1
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;
            }
        }
예제 #2
0
 void NavigationPropertyTo_Removed(object sender, EventArgs e)
 {
     _navigationPropertyTo = null;
 }
 /// <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;
     }
 }
 void NavigationPropertyTo_Removed(object sender, EventArgs e)
 {
     _navigationPropertyTo = null;
 }