internal StoreMemberProperty(EDMXFile parentFile, StoreEntityType storeEntityType, string name, int ordinal, XmlElement parentTypeElement)
            : base(parentFile)
        {
            _parentEntityType          = storeEntityType;
            _parentEntityType.Removed += new EventHandler(ParentEntityType_Removed);

            _propertyElement = EDMXDocument.CreateElement("Property", NameSpaceURIssdl);
            if (ordinal > 0)
            {
                XmlNodeList propertyNodes = parentTypeElement.SelectNodes("ssdl:Property", NSM);
                if (propertyNodes.Count >= ordinal)
                {
                    parentTypeElement.InsertAfter(_propertyElement, propertyNodes[ordinal - 1]);
                }
                else
                {
                    parentTypeElement.AppendChild(_propertyElement);
                }
            }
            else
            {
                parentTypeElement.AppendChild(_propertyElement);
            }

            this.Name = name;
        }
 internal StoreMemberProperty(EDMXFile parentFile, StoreEntityType parentEntityType, XmlElement propertyElement)
     : base(parentFile)
 {
     _parentEntityType          = parentEntityType;
     _parentEntityType.Removed += new EventHandler(ParentEntityType_Removed);
     _propertyElement           = propertyElement;
 }
        internal StoreAssociationSet(EDMXFile parentFile, StorageModel storageModel, string name, StoreEntitySet fromES, StoreEntitySet toES, StoreEntityType fromET, StoreEntityType toET, string fromRoleName, string toRoleName, MultiplicityTypeEnum fromMultiplicity, MultiplicityTypeEnum toMultiplicity, List<Tuple<StoreMemberProperty, StoreMemberProperty>> keys)
            : base(parentFile)
        {
            _storageModel = storageModel;

            _associationSetElement = CreateAssociationSet();
            _associationElement = CreateAssociation(name);

            Name = name;

            FromRoleName = fromRoleName;
            ToRoleName = toRoleName;

            FromEntitySet = fromES;
            FromEntityType = fromET;
            FromMultiplicity = fromMultiplicity;

            ToEntitySet = toES;
            ToEntityType = toET;
            ToMultiplicity = toMultiplicity;

            foreach (Tuple<StoreMemberProperty, StoreMemberProperty> key in keys)
            {
                AddKey(key.Item1, key.Item2);
            }

            _keysEnumerated = true;
        }
        internal void UpdateKeyName(StoreEntityType entityType, StoreMemberProperty memberProperty, string oldName, string newName)
        {
            if (_associationElement == null)
            {
                throw new InvalidOperationException("The association set doesn't have a corresponding association.");
            }

            if (entityType == FromEntitySet.EntityType)
            {
                foreach (XmlElement key in _associationElement.SelectNodes("ssdl:ReferentialConstraint/ssdl:Dependent/ssdl:PropertyRef[@Name=" + XmlHelpers.XPathLiteral(oldName) + "]", NSM))
                {
                    key.SetAttribute("Name", newName);
                }
            }
            else if (entityType == ToEntitySet.EntityType)
            {
                foreach (XmlElement key in _associationElement.SelectNodes("ssdl:ReferentialConstraint/ssdl:Principal/ssdl: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);
            }
        }
        internal StoreAssociationSet(EDMXFile parentFile, StorageModel storageModel, string name, StoreEntitySet fromES, StoreEntitySet toES, StoreEntityType fromET, StoreEntityType toET, string fromRoleName, string toRoleName, MultiplicityTypeEnum fromMultiplicity, MultiplicityTypeEnum toMultiplicity, List <Tuple <StoreMemberProperty, StoreMemberProperty> > keys)
            : base(parentFile)
        {
            _storageModel = storageModel;

            _associationSetElement = CreateAssociationSet();
            _associationElement    = CreateAssociation(name);

            Name = name;

            FromRoleName = fromRoleName;
            ToRoleName   = toRoleName;

            FromEntitySet    = fromES;
            FromEntityType   = fromET;
            FromMultiplicity = fromMultiplicity;

            ToEntitySet    = toES;
            ToEntityType   = toET;
            ToMultiplicity = toMultiplicity;

            foreach (Tuple <StoreMemberProperty, StoreMemberProperty> key in keys)
            {
                AddKey(key.Item1, key.Item2);
            }

            _keysEnumerated = true;
        }
        internal StoreMemberProperty(EDMXFile parentFile, StoreEntityType storeEntityType, string name, int ordinal, XmlElement parentTypeElement)
            : base(parentFile)
        {
            _parentEntityType = storeEntityType;
            _parentEntityType.Removed += new EventHandler(ParentEntityType_Removed);

            _propertyElement = EDMXDocument.CreateElement("Property", NameSpaceURIssdl);
            if (ordinal > 0)
            {
                XmlNodeList propertyNodes = parentTypeElement.SelectNodes("ssdl:Property", NSM);
                if (propertyNodes.Count >= ordinal)
                {
                    parentTypeElement.InsertAfter(_propertyElement, propertyNodes[ordinal - 1]);
                }
                else
                {
                    parentTypeElement.AppendChild(_propertyElement);
                }
            }
            else
            {
                parentTypeElement.AppendChild(_propertyElement);
            }

            this.Name = name;
        }
 internal StoreMemberProperty(EDMXFile parentFile, StoreEntityType parentEntityType, XmlElement propertyElement)
     : base(parentFile)
 {
     _parentEntityType = parentEntityType;
     _parentEntityType.Removed += new EventHandler(ParentEntityType_Removed);
     _propertyElement = propertyElement;
 }
예제 #8
0
        /// <summary>
        /// Retrieves an existing entitytype based on a conceptual model entittype, or creates a new one if a match can not be found.
        /// </summary>
        /// <param name="modelEntityType">Conceptual model entity type to match.</param>
        /// <returns>A StoreEntityType object.</returns>
        public StoreEntityType GetOrCreateEntityType(ModelEntityType modelEntityType)
        {
            StoreEntityType storeEntityType = EntityTypes.FirstOrDefault(et => et.Name.Equals(modelEntityType.Name, StringComparison.InvariantCultureIgnoreCase));

            if (storeEntityType == null)
            {
                storeEntityType = AddEntityType(modelEntityType);
            }
            return(storeEntityType);
        }
예제 #9
0
        /// <summary>
        /// Adds a new entity type to the storage model, based on an existing conceptual model entity type.
        /// </summary>
        /// <param name="modelEntityType">Conceptual model entity type to use as a base.</param>
        /// <returns>A new StoreEntityType object.</returns>
        public StoreEntityType AddEntityType(ModelEntityType modelEntityType)
        {
            StoreEntityType storeEntityType = this.AddEntityType(modelEntityType.Name);

            if (!string.IsNullOrEmpty(modelEntityType.ShortDescription))
            {
                storeEntityType.ShortDescription = modelEntityType.ShortDescription;
            }
            if (!string.IsNullOrEmpty(modelEntityType.LongDescription))
            {
                storeEntityType.LongDescription = modelEntityType.LongDescription;
            }
            return(storeEntityType);
        }
예제 #10
0
 /// <summary>
 /// Adds a new entity type to the storage model.
 /// </summary>
 /// <param name="name">Entity type name from the new entitytype.</param>
 /// <returns>A new StoreEntityType object.</returns>
 public StoreEntityType AddEntityType(string name)
 {
     if (!EntityTypes.Where(et => et.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase)).Any())
     {
         StoreEntityType et = new StoreEntityType(ParentFile, this, name);
         _storeEntityTypes.Add(name, et);
         et.NameChanged += new EventHandler <NameChangeArgs>(et_NameChanged);
         et.Removed     += new EventHandler(et_Removed);
         return(et);
     }
     else
     {
         throw new ArgumentException("An entity type with the name " + name + " already exist in the model.");
     }
 }
예제 #11
0
        /// <summary>
        /// Adds a new entity type mapping to this entity set mapping. Used for adding inherited sub-types to an entity set mapping
        /// </summary>
        /// <param name="modelEntityType">Conceptual model entity type to add to the mapping</param>
        /// <param name="storeEntityType">Store entity type mapped to the conceptual model entity type</param>
        public void AddEntityTypeMapping(ModelEntityType modelEntityType, StoreEntityType storeEntityType)
        {
            string storeEntitySetName = storeEntityType.EntitySet.Name;

            //get hold of the type mapping
            XmlElement entityTypeMapping = (XmlElement)_esmElement.SelectSingleNode("map:EntityTypeMapping[@TypeName=" + XmlHelpers.XPathLiteral(modelEntityType.FullName) + " or @TypeName=" + XmlHelpers.XPathLiteral("IsTypeOf(" + modelEntityType.FullName + ")") + " or @TypeName=" + XmlHelpers.XPathLiteral(modelEntityType.AliasName) + " or @TypeName=" + XmlHelpers.XPathLiteral("IsTypeOf(" + modelEntityType.AliasName + ")") + "]", NSM);

            if (entityTypeMapping == null)
            {
                //not found - create
                entityTypeMapping = EDMXDocument.CreateElement("EntityTypeMapping", NameSpaceURImap);
                _esmElement.AppendChild(entityTypeMapping);

                if ((modelEntityType.HasBaseType || modelEntityType.HasSubTypes) &&
                    this.ModelEntitySet.InheritanceStrategy != EDMXInheritanceStrategyEnum.TPC)
                {
                    entityTypeMapping.SetAttribute("TypeName", "IsTypeOf(" + modelEntityType.FullName + ")");
                }
                else
                {
                    entityTypeMapping.SetAttribute("TypeName", modelEntityType.FullName);
                }
            }

            XmlElement mappingFragment = (XmlElement)entityTypeMapping.SelectSingleNode("map:MappingFragment[@StoreEntitySet=" + XmlHelpers.XPathLiteral(storeEntitySetName) + "]", NSM);

            if (mappingFragment == null)
            {
                mappingFragment = EDMXDocument.CreateElement("MappingFragment", NameSpaceURImap);
                entityTypeMapping.AppendChild(mappingFragment);

                mappingFragment.SetAttribute("StoreEntitySet", storeEntitySetName);

                if (_storeEntitySetsEnumerated == true)
                {
                    StoreEntitySet storeEntitySet = _csMapping.ParentFile.StorageModel.EntitySets.FirstOrDefault(es => es.Name == storeEntitySetName);
                    if (storeEntitySet != null)
                    {
                        storeEntitySet.Removed += new EventHandler(storeEntitySet_Removed);
                        _storeEntitySets.Add(storeEntitySet);
                    }
                }
            }
        }
예제 #12
0
 void entityType_Removed(object sender, EventArgs e)
 {
     _entityType = null;
 }
예제 #13
0
 /// <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.");
     }
 }
        internal void UpdateKeyName(StoreEntityType entityType, StoreMemberProperty memberProperty, string oldName, string newName)
        {
            if (_associationElement == null) { throw new InvalidOperationException("The association set doesn't have a corresponding association."); }

            if (entityType == FromEntitySet.EntityType)
            {
                foreach (XmlElement key in _associationElement.SelectNodes("ssdl:ReferentialConstraint/ssdl:Dependent/ssdl:PropertyRef[@Name=" + XmlHelpers.XPathLiteral(oldName) + "]", NSM))
                {
                    key.SetAttribute("Name", newName);
                }
            }
            else if (entityType == ToEntitySet.EntityType)
            {
                foreach (XmlElement key in _associationElement.SelectNodes("ssdl:ReferentialConstraint/ssdl:Principal/ssdl: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);
            }
        }
예제 #15
0
 /// <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.");
     }
 }
        /// <summary>
        /// Adds a new entity type mapping to this entity set mapping. Used for adding inherited sub-types to an entity set mapping
        /// </summary>
        /// <param name="modelEntityType">Conceptual model entity type to add to the mapping</param>
        /// <param name="storeEntityType">Store entity type mapped to the conceptual model entity type</param>
        public void AddEntityTypeMapping(ModelEntityType modelEntityType, StoreEntityType storeEntityType)
        {
            string storeEntitySetName = storeEntityType.EntitySet.Name;

            //get hold of the type mapping
            XmlElement entityTypeMapping = (XmlElement)_esmElement.SelectSingleNode("map:EntityTypeMapping[@TypeName=" + XmlHelpers.XPathLiteral(modelEntityType.FullName) + " or @TypeName=" + XmlHelpers.XPathLiteral("IsTypeOf(" + modelEntityType.FullName + ")") + " or @TypeName=" + XmlHelpers.XPathLiteral(modelEntityType.AliasName) + " or @TypeName=" + XmlHelpers.XPathLiteral("IsTypeOf(" + modelEntityType.AliasName + ")") + "]", NSM);
            if (entityTypeMapping == null)
            {
                //not found - create
                entityTypeMapping = EDMXDocument.CreateElement("EntityTypeMapping", NameSpaceURImap);
                _esmElement.AppendChild(entityTypeMapping);

                if ((modelEntityType.HasBaseType || modelEntityType.HasSubTypes)
                    && this.ModelEntitySet.InheritanceStrategy != EDMXInheritanceStrategyEnum.TPC)
                {
                    entityTypeMapping.SetAttribute("TypeName", "IsTypeOf(" + modelEntityType.FullName + ")");
                }
                else
                {
                    entityTypeMapping.SetAttribute("TypeName", modelEntityType.FullName);
                }
            }

            XmlElement mappingFragment = (XmlElement)entityTypeMapping.SelectSingleNode("map:MappingFragment[@StoreEntitySet=" + XmlHelpers.XPathLiteral(storeEntitySetName) + "]", NSM);
            if (mappingFragment == null)
            {
                mappingFragment = EDMXDocument.CreateElement("MappingFragment", NameSpaceURImap);
                entityTypeMapping.AppendChild(mappingFragment);

                mappingFragment.SetAttribute("StoreEntitySet", storeEntitySetName);

                if (_storeEntitySetsEnumerated == true)
                {
                    StoreEntitySet storeEntitySet = _csMapping.ParentFile.StorageModel.EntitySets.FirstOrDefault(es => es.Name == storeEntitySetName);
                    if (storeEntitySet != null)
                    {
                        storeEntitySet.Removed += new EventHandler(storeEntitySet_Removed);
                        _storeEntitySets.Add(storeEntitySet);
                    }
                }
            }
        }
예제 #17
0
 /// <summary>
 /// Adds a new entity type to the storage model.
 /// </summary>
 /// <param name="name">Entity type name from the new entitytype.</param>
 /// <returns>A new StoreEntityType object.</returns>
 public StoreEntityType AddEntityType(string name)
 {
     if (!EntityTypes.Where(et => et.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase)).Any())
     {
         StoreEntityType et = new StoreEntityType(ParentFile, this, name);
         _storeEntityTypes.Add(name, et);
         et.NameChanged += new EventHandler<NameChangeArgs>(et_NameChanged);
         et.Removed += new EventHandler(et_Removed);
         return et;
     }
     else
     {
         throw new ArgumentException("An entity type with the name " + name + " already exist in the model.");
     }
 }
예제 #18
0
 void entityType_Removed(object sender, EventArgs e)
 {
     _entityType = null;
 }