/// <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; } }
/// <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; } }