Beispiel #1
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;
     }
 }
Beispiel #2
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;
     }
 }
        internal NavigationProperty(EDMXFile parentFile, ModelEntityType modelEntityType, string name, ModelAssociationSet modelAssociationSet, XmlElement entityTypeElement, string fromRoleName, string toRoleName)
            : base(parentFile)
        {
            _modelEntityType = modelEntityType;

            _propertyElement = EDMXDocument.CreateElement("NavigationProperty", NameSpaceURIcsdl);
            _propertyElement.SetAttribute("Relationship", modelAssociationSet.FullName);

            if (string.IsNullOrEmpty(fromRoleName) || string.IsNullOrEmpty(toRoleName))
            {
                if (modelAssociationSet.FromEntityType == _modelEntityType)
                {
                    fromRoleName = modelAssociationSet.FromRoleName;
                    toRoleName = modelAssociationSet.ToRoleName;
                }
                else
                {
                    fromRoleName = modelAssociationSet.ToRoleName;
                    toRoleName = modelAssociationSet.FromRoleName;
                }
            }

            _propertyElement.SetAttribute("FromRole", fromRoleName);
            _propertyElement.SetAttribute("ToRole", toRoleName);

            entityTypeElement.AppendChild(_propertyElement);

            Name = name;
        }
        internal AssociationSetMapping(EDMXFile parentFile, XmlElement entityContainerMappingElement, CSMapping csMapping, string name, ModelAssociationSet modelAssocSet, StoreEntitySet storeEntitySet, StoreAssociationSet fromStoreAssocSet, StoreAssociationSet toStoreAssocSet)
            : base(parentFile)
        {
            _csMapping           = csMapping;
            _modelAssociationSet = modelAssocSet;

            //create mapping xml elements
            _asmElement = EDMXDocument.CreateElement("AssociationSetMapping", NameSpaceURImap);
            entityContainerMappingElement.AppendChild(_asmElement);

            XmlElement fromEndProp = EDMXDocument.CreateElement("EndProperty", NameSpaceURImap);

            fromEndProp.SetAttribute("Name", modelAssocSet.FromRoleName);
            _asmElement.AppendChild(fromEndProp);

            XmlElement toEndProp = EDMXDocument.CreateElement("EndProperty", NameSpaceURImap);

            toEndProp.SetAttribute("Name", modelAssocSet.ToRoleName);
            _asmElement.AppendChild(toEndProp);

            List <Tuple <ModelMemberProperty, StoreMemberProperty, string> > fromKeys = (
                from key in fromStoreAssocSet.Keys
                select new Tuple <ModelMemberProperty, StoreMemberProperty, string>(
                    key.Item2.ModelMembers.FirstOrDefault(mm => mm.EntityType == modelAssocSet.FromEntityType),
                    key.Item1,
                    key.Item2.Name
                    )
                ).ToList();

            foreach (var key in fromKeys)
            {
                XmlElement scalarProperty = EDMXDocument.CreateElement("ScalarProperty", NameSpaceURImap);
                scalarProperty.SetAttribute("Name", (key.Item1 != null ? key.Item1.Name : key.Item3));
                scalarProperty.SetAttribute("ColumnName", key.Item2.Name);
                fromEndProp.AppendChild(scalarProperty);
            }

            List <Tuple <ModelMemberProperty, StoreMemberProperty, string> > toKeys =
                (
                    from key in toStoreAssocSet.Keys
                    select new Tuple <ModelMemberProperty, StoreMemberProperty, string>(
                        key.Item2.ModelMembers.FirstOrDefault(mm => mm.EntityType == modelAssocSet.ToEntityType),
                        key.Item1,
                        key.Item2.Name
                        )
                ).ToList();

            foreach (var key in toKeys)
            {
                XmlElement scalarProperty = EDMXDocument.CreateElement("ScalarProperty", NameSpaceURImap);
                scalarProperty.SetAttribute("Name", (key.Item1 != null ? key.Item1.Name : key.Item3));
                scalarProperty.SetAttribute("ColumnName", key.Item2.Name);
                toEndProp.AppendChild(scalarProperty);
            }

            Name = name;
            StoreEntitySetName = storeEntitySet.Name;
            TypeName           = modelAssocSet.FullName;
        }
Beispiel #5
0
        /// <summary>
        /// Adds an association set mapping between a model association set and store association set.
        /// </summary>
        /// <param name="name">Mapping name</param>
        /// <param name="modelAssociationSet">Model association set.</param>
        /// <param name="storeAssociationSet">Store association set.</param>
        /// <returns></returns>
        public AssociationSetMapping AddAssociationMapping(string name, ModelAssociationSet modelAssociationSet, StoreAssociationSet storeAssociationSet)
        {
            AssociationSetMapping asm = new AssociationSetMapping(base.ParentFile, _entityContainerMapping, this, name, modelAssociationSet, storeAssociationSet);

            _associationSetMappings.Add(asm.Name, asm);
            asm.NameChanged += new EventHandler <NameChangeArgs>(asm_NameChanged);
            asm.Removed     += new EventHandler(asm_Removed);
            return(asm);
        }
        internal AssociationSetMapping(EDMXFile parentFile, XmlElement entityContainerMappingElement, CSMapping csMapping, string name, ModelAssociationSet modelAssocSet, StoreEntitySet storeEntitySet, StoreAssociationSet fromStoreAssocSet, StoreAssociationSet toStoreAssocSet)
            : base(parentFile)
        {
            _csMapping = csMapping;
            _modelAssociationSet = modelAssocSet;

            //create mapping xml elements
            _asmElement = EDMXDocument.CreateElement("AssociationSetMapping", NameSpaceURImap);
            entityContainerMappingElement.AppendChild(_asmElement);

            XmlElement fromEndProp = EDMXDocument.CreateElement("EndProperty", NameSpaceURImap);
            fromEndProp.SetAttribute("Name", modelAssocSet.FromRoleName);
            _asmElement.AppendChild(fromEndProp);

            XmlElement toEndProp = EDMXDocument.CreateElement("EndProperty", NameSpaceURImap);
            toEndProp.SetAttribute("Name", modelAssocSet.ToRoleName);
            _asmElement.AppendChild(toEndProp);

            List<Tuple<ModelMemberProperty, StoreMemberProperty, string>> fromKeys = (
                from key in fromStoreAssocSet.Keys
                select new Tuple<ModelMemberProperty, StoreMemberProperty, string>(
                    key.Item2.ModelMembers.FirstOrDefault(mm => mm.EntityType == modelAssocSet.FromEntityType),
                    key.Item1,
                    key.Item2.Name
                    )
                ).ToList();
            foreach (var key in fromKeys)
            {
                XmlElement scalarProperty = EDMXDocument.CreateElement("ScalarProperty", NameSpaceURImap);
                scalarProperty.SetAttribute("Name", (key.Item1 != null ? key.Item1.Name : key.Item3));
                scalarProperty.SetAttribute("ColumnName", key.Item2.Name);
                fromEndProp.AppendChild(scalarProperty);
            }

            List<Tuple<ModelMemberProperty, StoreMemberProperty, string>> toKeys =
                (
                from key in toStoreAssocSet.Keys
                select new Tuple<ModelMemberProperty, StoreMemberProperty, string>(
                    key.Item2.ModelMembers.FirstOrDefault(mm => mm.EntityType == modelAssocSet.ToEntityType),
                    key.Item1,
                    key.Item2.Name
                    )
                ).ToList();
            foreach (var key in toKeys)
            {
                XmlElement scalarProperty = EDMXDocument.CreateElement("ScalarProperty", NameSpaceURImap);
                scalarProperty.SetAttribute("Name", (key.Item1 != null ? key.Item1.Name : key.Item3));
                scalarProperty.SetAttribute("ColumnName", key.Item2.Name);
                toEndProp.AppendChild(scalarProperty);
            }

            Name = name;
            StoreEntitySetName = storeEntitySet.Name;
            TypeName = modelAssocSet.FullName;
        }
Beispiel #7
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>
 /// <returns>A NavigationProperty object.</returns>
 public NavigationProperty AddNavigationMember(string navigationPropertyName, ModelAssociationSet modelAssociationSet)
 {
     return(AddNavigationMember(navigationPropertyName, modelAssociationSet, null, null));
 }
 void ModelAssociationSet_Removed(object sender, EventArgs e)
 {
     this.Remove();
     _modelAssociationSet = null;
 }
 /// <summary>
 /// Adds an association set mapping between a model association set and store association set.
 /// </summary>
 /// <param name="name">Mapping name</param>
 /// <param name="modelAssociationSet">Model association set.</param>
 /// <param name="storeAssociationSet">Store association set.</param>
 /// <returns></returns>
 public AssociationSetMapping AddAssociationMapping(string name, ModelAssociationSet modelAssociationSet, StoreAssociationSet storeAssociationSet)
 {
     AssociationSetMapping asm = new AssociationSetMapping(base.ParentFile, _entityContainerMapping, this, name, modelAssociationSet, storeAssociationSet);
     _associationSetMappings.Add(asm.Name, asm);
     asm.NameChanged += new EventHandler<NameChangeArgs>(asm_NameChanged);
     asm.Removed += new EventHandler(asm_Removed);
     return asm;
 }
        internal NavigationProperty(EDMXFile parentFile, ModelEntityType modelEntityType, string name, ModelAssociationSet modelAssociationSet, XmlElement entityTypeElement, string fromRoleName, string toRoleName)
            : base(parentFile)
        {
            _modelEntityType = modelEntityType;

            _propertyElement = EDMXDocument.CreateElement("NavigationProperty", NameSpaceURIcsdl);
            _propertyElement.SetAttribute("Relationship", modelAssociationSet.FullName);

            if (string.IsNullOrEmpty(fromRoleName) || string.IsNullOrEmpty(toRoleName))
            {
                if (modelAssociationSet.FromEntityType == _modelEntityType)
                {
                    fromRoleName = modelAssociationSet.FromRoleName;
                    toRoleName   = modelAssociationSet.ToRoleName;
                }
                else
                {
                    fromRoleName = modelAssociationSet.ToRoleName;
                    toRoleName   = modelAssociationSet.FromRoleName;
                }
            }

            _propertyElement.SetAttribute("FromRole", fromRoleName);
            _propertyElement.SetAttribute("ToRole", toRoleName);

            entityTypeElement.AppendChild(_propertyElement);

            Name = name;
        }
 void ModelAssociationSet_Removed(object sender, EventArgs e)
 {
     this.Remove();
     _modelAssociationSet = null;
 }
 /// <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 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 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>
 /// <returns>A NavigationProperty object.</returns>
 public NavigationProperty AddNavigationMember(string navigationPropertyName, ModelAssociationSet modelAssociationSet)
 {
     return AddNavigationMember(navigationPropertyName, modelAssociationSet, null, null);
 }
 void modelAssociationSet_Removed(object sender, EventArgs e)
 {
     _modelAssociationSet = null;
 }
 void modelAssociationSet_Removed(object sender, EventArgs e)
 {
     _modelAssociationSet = null;
 }