示例#1
0
 /// <summary>
 /// Adds a new association set and association between two conceptual model entities.
 /// </summary>
 /// <param name="name">Name of the association and association set.</param>
 /// <param name="fromEntitySet">Entity set where the entity set originates from. For one-to-many associations, this is typically the many-side of the association.</param>
 /// <param name="toEntitySet">Entity set that the entity set references.</param>
 /// <param name="fromEntityType">Entity type that the association originates from. This should be the entity type or a descendant of the entity type for the entity set passed in the fromEntitySet parameter.</param>
 /// <param name="toEntityType">Entity type that the association references. This should be the entity type or a descendant of the entity type that the entity set passed in the toEntitySet parameter.</param>
 /// <param name="fromMultiplicity">Multiplicity for the from entity set.</param>
 /// <param name="toMultiplicity">Multiplicity for the to entity set.</param>
 /// <param name="fromNavigationProperty">Name for the conceptual model navigation property in the fromEntityType for the association.</param>
 /// <param name="toNavigationProperty">Name for the conceptual model navigation property in the toEntityType for the association.</param>
 /// <param name="keys">A list of the entity key pairs for the association. This is a list containing pairs of ModelMemberProperty instances from the From and To entity types.</param>
 /// <returns></returns>
 public ModelAssociationSet AddAssociation(string name, ModelEntitySet fromEntitySet, ModelEntitySet toEntitySet, ModelEntityType fromEntityType, ModelEntityType toEntityType, MultiplicityTypeEnum fromMultiplicity, MultiplicityTypeEnum toMultiplicity, string fromNavigationProperty, string toNavigationProperty, List <Tuple <ModelMemberProperty, ModelMemberProperty> > keys)
 {
     try
     {
         if (!AssociationSets.Where(et => et.Name == name).Any())
         {
             ModelAssociationSet mas = new ModelAssociationSet(this.ParentFile, this, name, fromEntitySet, toEntitySet, fromEntityType, toEntityType, fromMultiplicity, toMultiplicity, fromNavigationProperty, toNavigationProperty, keys);
             _modelAssociationSets.Add(mas.Name, mas);
             mas.NameChanged += new EventHandler <NameChangeArgs>(aset_NameChanged);
             mas.Removed     += new EventHandler(aset_Removed);
             return(mas);
         }
         else
         {
             throw new ArgumentException("An association named " + name + " already exists in the model.");
         }
     }
     catch (Exception ex)
     {
         try
         {
             if (!ex.Data.Contains("EDMXType"))
             {
                 ex.Data.Add("EDMXType", this.GetType().Name);
             }
             if (!ex.Data.Contains("EDMXObjectName"))
             {
                 ex.Data.Add("EDMXObjectName", this.ContainerName);
             }
         }
         catch { }
         throw;
     }
 }
 /// <summary>
 /// Adds a new association between two store entitysets.
 /// </summary>
 /// <param name="name">Name of the association, typically the foreign key name.</param>
 /// <param name="fromEntitySet">From-entityset.</param>
 /// <param name="toEntitySet">To-entityset.</param>
 /// <param name="fromEntityType">From-entitytype. This must be an entity type associated with the from-entityset, or part of the same inheritance structure.</param>
 /// <param name="toEntityType">To-entitytype. This must be an entity type associated with the to-entityset, or part of the same inheritance structure.</param>
 /// <param name="fromRoleName">From-role</param>
 /// <param name="toRoleName">To-role</param>
 /// <param name="fromMultiplicity">From-multiplicity.</param>
 /// <param name="toMultiplicity">To-multiplicity.</param>
 /// <param name="keys">Pairs of the foreign key / association scalar members enforcing the association/foreign key constraint.</param>
 /// <returns></returns>
 public StoreAssociationSet AddAssociation(string name, StoreEntitySet fromEntitySet, StoreEntitySet toEntitySet, StoreEntityType fromEntityType, StoreEntityType toEntityType, string fromRoleName, string toRoleName, MultiplicityTypeEnum fromMultiplicity, MultiplicityTypeEnum toMultiplicity, List <Tuple <StoreMemberProperty, StoreMemberProperty> > keys)
 {
     if (!AssociationSets.Where(et => et.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase)).Any())
     {
         StoreAssociationSet sas = new StoreAssociationSet(this.ParentFile, this, name, fromEntitySet, toEntitySet, fromEntityType, toEntityType, fromRoleName, toRoleName, fromMultiplicity, toMultiplicity, keys);
         _storeAssociationSets.Add(sas.Name, sas);
         sas.NameChanged += new EventHandler <NameChangeArgs>(aset_NameChanged);
         sas.Removed     += new EventHandler(aset_Removed);
         return(sas);
     }
     else
     {
         throw new ArgumentException("An association named " + name + " already exists in the model.");
     }
 }
示例#3
0
 /// <summary>
 /// Removes all members from the conceptual model.
 /// </summary>
 public void Clear()
 {
     try
     {
         foreach (ModelAssociationSet mas in AssociationSets.ToList())
         {
             mas.Remove();
         }
         foreach (ModelComplexType mct in ComplexTypes.ToList())
         {
             mct.Remove();
         }
         foreach (ModelEntityType met in EntityTypes.ToList())
         {
             met.Remove();
         }
         foreach (ModelEntitySet mes in EntitySets.ToList())
         {
             mes.Remove();
         }
         foreach (ModelFunction mf in FunctionImports.ToList())
         {
             mf.Remove();
         }
     }
     catch (Exception ex)
     {
         try
         {
             if (!ex.Data.Contains("EDMXType"))
             {
                 ex.Data.Add("EDMXType", this.GetType().Name);
             }
             if (!ex.Data.Contains("EDMXObjectName"))
             {
                 ex.Data.Add("EDMXObjectName", this.ContainerName);
             }
         }
         catch { }
         throw;
     }
 }