/// <summary>
        /// Adds a store entityset to the model, based on an existing conceptual model entity set and entity type.
        /// </summary>
        /// <param name="modelEntitySet">Conceptual model entity set</param>
        /// <param name="modelEntityType">Conceptual model entity type</param>
        /// <param name="schemaName">Database schemaname for the new entity set.</param>
        /// <param name="tableName">Tablename for the new entityset.</param>
        /// <returns>A new StoreEntitySet object.</returns>
        public StoreEntitySet AddEntitySet(ModelEntitySet modelEntitySet, ModelEntityType modelEntityType, string schemaName, string tableName)
        {
            string entitySetName = null;

            if (!modelEntityType.HasBaseType)
            {
                entitySetName = modelEntitySet.Name;
            }
            else
            {
                entitySetName = modelEntityType.TopLevelBaseType.EntitySet.Name + "_" + modelEntityType.Name;// string.Join("_", modelEntityType.BaseTypes.Select(tn => tn.Name));
            }

            StoreEntitySet storeEntitySet = this.AddEntitySet(entitySetName);

            storeEntitySet.StoreType = StoreTypeEnum.Table;
            storeEntitySet.Schema    = schemaName;
            storeEntitySet.TableName = tableName;
            if (!string.IsNullOrEmpty(modelEntitySet.ShortDescription))
            {
                storeEntitySet.ShortDescription = modelEntitySet.ShortDescription;
            }
            if (!string.IsNullOrEmpty(modelEntitySet.LongDescription))
            {
                storeEntitySet.LongDescription = modelEntitySet.LongDescription;
            }
            return(storeEntitySet);
        }
        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 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;
        }
        /// <summary>
        /// Retrieves an existing entityset by name, or creates a new one if no matching entity set exist in the storage model.
        /// </summary>
        /// <param name="entitySetName">Name of the entity set to get or create.</param>
        /// <returns>A StoreEntitySet object.</returns>
        public StoreEntitySet GetOrCreateEntitySet(string entitySetName)
        {
            StoreEntitySet storeEntitySet = EntitySets.FirstOrDefault(es => es.Name.Equals(entitySetName, StringComparison.InvariantCultureIgnoreCase));

            if (storeEntitySet == null)
            {
                storeEntitySet = AddEntitySet(entitySetName);
            }
            return(storeEntitySet);
        }
        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;
        }
 /// <summary>
 /// Adds a new entity set to the storage model.
 /// </summary>
 /// <param name="name">Entity set name for the new entityset.</param>
 /// <returns>A new StoreEntitySet object.</returns>
 public StoreEntitySet AddEntitySet(string name)
 {
     if (!EntitySets.Where(es => es.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase)).Any())
     {
         StoreEntitySet es = new StoreEntitySet(ParentFile, this, name);
         _storeEntitySets.Add(name, es);
         es.NameChanged += new EventHandler <NameChangeArgs>(es_NameChanged);
         es.Removed     += new EventHandler(es_Removed);
         return(es);
     }
     else
     {
         throw new ArgumentException("An entity set with the name " + name + " already exist in the model.");
     }
 }
 /// <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.");
     }
 }
Beispiel #8
0
        private void EnumerateStoreEntitySets()
        {
            XmlNodeList mappingFragmentElements = _esmElement.SelectNodes("map:EntityTypeMapping/map:MappingFragment", NSM);

            foreach (XmlElement mappingFragmentElement in mappingFragmentElements)
            {
                string         storeEntitySetName = mappingFragmentElement.GetAttribute("StoreEntitySet");
                StoreEntitySet storeEntitySet     = _csMapping.ParentFile.StorageModel.EntitySets.FirstOrDefault(es => es.Name.Equals(storeEntitySetName, StringComparison.InvariantCultureIgnoreCase));
                if (storeEntitySet != null)
                {
                    storeEntitySet.Removed += new EventHandler(storeEntitySet_Removed);
                    _storeEntitySets.Add(storeEntitySet);
                }
            }
            _storeEntitySetsEnumerated = true;
        }
Beispiel #9
0
        /// <summary>
        /// Returns all store entitysets mapped to the specified conceptual model entity type
        /// </summary>
        /// <param name="modelEntityType">A conceptual model entity type</param>
        /// <returns>An enumeration of the store entitysets mapped to the specified conceptual model entity type</returns>
        public IEnumerable <StoreEntitySet> StoreEntitySetsFor(ModelEntityType modelEntityType)
        {
            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)
            {
                foreach (XmlElement mappingFragment in entityTypeMapping.SelectNodes("map:MappingFragment", NSM))
                {
                    string         storeEntitySetName = mappingFragment.GetAttribute("StoreEntitySet");
                    StoreEntitySet storeEntitySet     = StoreEntitySets.FirstOrDefault(ses => ses.Name.Equals(storeEntitySetName, StringComparison.InvariantCultureIgnoreCase));
                    if (storeEntitySet != null)
                    {
                        yield return(storeEntitySet);
                    }
                }
            }
        }
Beispiel #10
0
        /// <summary>
        /// Returns the entity type mapped to the specified store entity set
        /// </summary>
        /// <param name="storeEntitySet">A store entityset that is mapped with this EntitySetMapping</param>
        /// <returns>An entity type object for the entity type mapped to the specified store entityset</returns>
        public ModelEntityType EntityTypeFor(StoreEntitySet storeEntitySet)
        {
            string     storeEntitySetName = storeEntitySet.Name;
            XmlElement mappingFragment    = (XmlElement)_esmElement.SelectSingleNode("map:EntityTypeMapping/map:MappingFragment[@StoreEntitySet=" + XmlHelpers.XPathLiteral(storeEntitySetName) + "]", NSM);

            if (mappingFragment != null)
            {
                string entityTypeName = EDMXUtils.StripTypeOf(((XmlElement)mappingFragment.ParentNode).GetAttribute("TypeName"));

                ModelEntityType entityType = ParentFile.ConceptualModel.EntityTypes.FirstOrDefault(et => et.FullName == entityTypeName || et.AliasName == entityTypeName);
                return(entityType);
            }
            else
            {
                return(null);
            }
        }
        internal EntitySetMapping(EDMXFile parentFile, XmlElement entityContainerMappingElement, CSMapping csMapping, ModelEntitySet modelEntitySet, StoreEntitySet[] storeEntitySets)
            : base(parentFile)
        {
            _csMapping = csMapping;

            //create mapping xml elements
            _esmElement = EDMXDocument.CreateElement("EntitySetMapping", NameSpaceURImap);
            _esmElement.SetAttribute("Name", modelEntitySet.Name);
            entityContainerMappingElement.AppendChild(_esmElement);

            //entity type mapping
            XmlElement entityTypeMapping = EDMXDocument.CreateElement("EntityTypeMapping", NameSpaceURImap);
            if ((modelEntitySet.EntityType.HasBaseType || modelEntitySet.EntityType.HasSubTypes) && modelEntitySet.InheritanceStrategy != EDMXInheritanceStrategyEnum.TPC)
            {
                entityTypeMapping.SetAttribute("TypeName", "IsTypeOf(" + modelEntitySet.EntityType.FullName + ")");
            }
            else
            {
                entityTypeMapping.SetAttribute("TypeName", modelEntitySet.EntityType.FullName);
            }
            _esmElement.AppendChild(entityTypeMapping);

            foreach (StoreEntitySet ses in storeEntitySets)
            {
                //mapping fragment wrapper
                XmlElement mappingFragment = EDMXDocument.CreateElement("MappingFragment", NameSpaceURImap);
                mappingFragment.SetAttribute("StoreEntitySet", ses.Name);
                entityTypeMapping.AppendChild(mappingFragment);
            }

            //keep references to entity sets...
            _modelEntitySet = modelEntitySet;
            _storeEntitySets.AddRange(storeEntitySets);

            //let the involved entity sets know about the change in mappings...
            modelEntitySet.CSMappingsUpdated();
            storeEntitySets.ToList().ForEach(es => es.CSMappingsUpdated());

            //hook up remove events
            _modelEntitySet.Removed += new EventHandler(modelEntitySet_Removed);
            foreach (StoreEntitySet ses in _storeEntitySets)
            {
                ses.Removed += new EventHandler(storeEntitySet_Removed);
            }
        }
Beispiel #12
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);
                    }
                }
            }
        }
        /// <summary>
        /// Retrieves an existing entityset based on a conceptual model entityset/type, or creates a new one if a match can not be found.
        /// </summary>
        /// <param name="modelEntitySet">Conceptual model entity set to match.</param>
        /// <param name="modelEntityType">Conceptual model entity type to match.</param>
        /// <param name="schemaName">Database schemaname for the new entity set.</param>
        /// <param name="tableName">Tablename for the new entityset.</param>
        /// <returns>A StoreEntitySet object.</returns>
        public StoreEntitySet GetOrCreateEntitySet(ModelEntitySet modelEntitySet, ModelEntityType modelEntityType, string schemaName, string tableName)
        {
            string entitySetName = null;

            if (!modelEntityType.HasBaseType)
            {
                entitySetName = modelEntitySet.Name;
            }
            else
            {
                entitySetName = modelEntityType.TopLevelBaseType.EntitySet.Name + "_" + modelEntityType.Name;
            }

            StoreEntitySet storeEntitySet = EntitySets.FirstOrDefault(es => es.Name.Equals(entitySetName, StringComparison.InvariantCultureIgnoreCase));

            if (storeEntitySet == null)
            {
                storeEntitySet = AddEntitySet(modelEntitySet, modelEntityType, schemaName, tableName);
            }
            return(storeEntitySet);
        }
Beispiel #14
0
        /// <summary>
        /// Adds a member mapping from a conceptual model scalar member to a storage model scalar member, with a entity type specified
        /// </summary>
        /// <param name="modelMemberProperty">Conceptual model scalar member to map</param>
        /// <param name="storeMemberProperty">Storage model scalar member to map to</param>
        /// <param name="modelEntityType">Model entity type to specify in the EntityTypeMapping for this member mapping.</param>
        public void AddMemberMapping(ModelMemberProperty modelMemberProperty, StoreMemberProperty storeMemberProperty, ModelEntityType modelEntityType)
        {
            if (modelEntityType != _modelEntitySet.EntityType && !modelEntityType.IsSubtypeOf(_modelEntitySet.EntityType))
            {
                throw new ArgumentException("The model member does not belong to the mapped entity type or a subclass of the mapped entity type.");
            }

            if (storeMemberProperty.EntityType.EntitySet != null)
            {
                //find the appropriate mapping fragment
                string storeEntitySetName = storeMemberProperty.EntityType.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);

                    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.Equals(storeEntitySetName, StringComparison.InvariantCultureIgnoreCase));
                        if (storeEntitySet != null)
                        {
                            storeEntitySet.Removed += new EventHandler(storeEntitySet_Removed);
                            _storeEntitySets.Add(storeEntitySet);
                        }
                    }
                }

                if (mappingFragment != null)
                {
                    if (mappingFragment.SelectSingleNode("map:ScalarProperty[@Name=" + XmlHelpers.XPathLiteral(modelMemberProperty.Name) + "][@ColumnName=" + XmlHelpers.XPathLiteral(storeMemberProperty.Name) + "]", NSM) == null)
                    {
                        XmlElement scalarProperty = EDMXDocument.CreateElement("ScalarProperty", NameSpaceURImap);
                        scalarProperty.SetAttribute("Name", modelMemberProperty.Name);
                        scalarProperty.SetAttribute("ColumnName", storeMemberProperty.Name);
                        mappingFragment.AppendChild(scalarProperty);

                        _memberMappings.Add(new Tuple <StoreMemberProperty, ModelMemberProperty, ModelEntityType>(storeMemberProperty, modelMemberProperty, modelEntityType));

                        storeMemberProperty.Removed += new EventHandler(smp_Removed);
                        modelMemberProperty.Removed += new EventHandler(mmp_Removed);

                        storeMemberProperty.CSMappingsUpdated();
                        modelMemberProperty.CSMappingsUpdated();
                    }
                    else
                    {
                        System.Diagnostics.Debug.Assert(false);
                    }
                }
                else
                {
                    throw new ArgumentException("The store entity set " + storeEntitySetName + " is not associated with the model entity set " + this.ModelEntitySet.Name);
                }
            }
            else
            {
                throw new InvalidOperationException("The store entity type " + (storeMemberProperty.EntityType != null ? storeMemberProperty.EntityType.Name : "[unknown]") + " is not associated with an entity set.");
            }
        }
 /// <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="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>A new StoreAssociationSet object.</returns>
 public StoreAssociationSet AddAssociation(string name, StoreEntitySet fromEntitySet, StoreEntitySet toEntitySet, MultiplicityTypeEnum fromMultiplicity, MultiplicityTypeEnum toMultiplicity, List<Tuple<StoreMemberProperty, StoreMemberProperty>> keys)
 {
     return AddAssociation(name, fromEntitySet, toEntitySet, fromEntitySet.EntityType, toEntitySet.EntityType, fromEntitySet.EntityType.Name, toEntitySet.EntityType.Name, fromMultiplicity, toMultiplicity, keys);
 }
 void fromEntitySet_Removed(object sender, EventArgs e)
 {
     _fromEntitySet = null;
 }
 /// <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="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>A new StoreAssociationSet object.</returns>
 public StoreAssociationSet AddAssociation(string name, StoreEntitySet fromEntitySet, StoreEntitySet toEntitySet, MultiplicityTypeEnum fromMultiplicity, MultiplicityTypeEnum toMultiplicity, List <Tuple <StoreMemberProperty, StoreMemberProperty> > keys)
 {
     return(AddAssociation(name, fromEntitySet, toEntitySet, fromEntitySet.EntityType, toEntitySet.EntityType, fromEntitySet.EntityType.Name, toEntitySet.EntityType.Name, fromMultiplicity, toMultiplicity, keys));
 }
 /// <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 an association set mapping for a many-to-many relationship.
 /// </summary>
 /// <param name="name">Name of the association mapping.</param>
 /// <param name="modelAssociationSet">Model association set.</param>
 /// <param name="storeJunctionEntitySet">Store entity set acting as the junction table.</param>
 /// <param name="fromStoreAssocSet">First store association set making up the many-to-many mapping in the storage model.</param>
 /// <param name="toStoreAssocSet">Second store association set making up the many-to-many mapping in the storage model.</param>
 /// <returns>An AssociationSetMapping object.</returns>
 public AssociationSetMapping AddAssociationMapping(string name, ModelAssociationSet modelAssociationSet, StoreEntitySet storeJunctionEntitySet, StoreAssociationSet fromStoreAssocSet, StoreAssociationSet toStoreAssocSet)
 {
     AssociationSetMapping asm = new AssociationSetMapping(base.ParentFile, _entityContainerMapping, this, name, modelAssociationSet, storeJunctionEntitySet, fromStoreAssocSet, toStoreAssocSet);
     _associationSetMappings.Add(asm.Name, asm);
     asm.NameChanged += new EventHandler<NameChangeArgs>(asm_NameChanged);
     asm.Removed += new EventHandler(asm_Removed);
     return asm;
 }
 /// <summary>
 /// Adds a new entity set to the storage model.
 /// </summary>
 /// <param name="name">Entity set name for the new entityset.</param>
 /// <returns>A new StoreEntitySet object.</returns>
 public StoreEntitySet AddEntitySet(string name)
 {
     if (!EntitySets.Where(es => es.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase)).Any())
     {
         StoreEntitySet es = new StoreEntitySet(ParentFile, this, name);
         _storeEntitySets.Add(name, es);
         es.NameChanged += new EventHandler<NameChangeArgs>(es_NameChanged);
         es.Removed += new EventHandler(es_Removed);
         return es;
     }
     else
     {
         throw new ArgumentException("An entity set with the name " + name + " already exist in the model.");
     }
 }
        /// <summary>
        /// Returns the entity type mapped to the specified store entity set
        /// </summary>
        /// <param name="storeEntitySet">A store entityset that is mapped with this EntitySetMapping</param>
        /// <returns>An entity type object for the entity type mapped to the specified store entityset</returns>
        public ModelEntityType EntityTypeFor(StoreEntitySet storeEntitySet)
        {
            string storeEntitySetName = storeEntitySet.Name;
            XmlElement mappingFragment = (XmlElement)_esmElement.SelectSingleNode("map:EntityTypeMapping/map:MappingFragment[@StoreEntitySet=" + XmlHelpers.XPathLiteral(storeEntitySetName) + "]", NSM);
            if (mappingFragment != null)
            {
                string entityTypeName = EDMXUtils.StripTypeOf(((XmlElement)mappingFragment.ParentNode).GetAttribute("TypeName"));

                ModelEntityType entityType = ParentFile.ConceptualModel.EntityTypes.FirstOrDefault(et => et.FullName == entityTypeName || et.AliasName == entityTypeName);
                return entityType;
            }
            else
            {
                return null;
            }
        }
Beispiel #22
0
        /// <summary>
        /// Adds an association set mapping for a many-to-many relationship.
        /// </summary>
        /// <param name="name">Name of the association mapping.</param>
        /// <param name="modelAssociationSet">Model association set.</param>
        /// <param name="storeJunctionEntitySet">Store entity set acting as the junction table.</param>
        /// <param name="fromStoreAssocSet">First store association set making up the many-to-many mapping in the storage model.</param>
        /// <param name="toStoreAssocSet">Second store association set making up the many-to-many mapping in the storage model.</param>
        /// <returns>An AssociationSetMapping object.</returns>
        public AssociationSetMapping AddAssociationMapping(string name, ModelAssociationSet modelAssociationSet, StoreEntitySet storeJunctionEntitySet, StoreAssociationSet fromStoreAssocSet, StoreAssociationSet toStoreAssocSet)
        {
            AssociationSetMapping asm = new AssociationSetMapping(base.ParentFile, _entityContainerMapping, this, name, modelAssociationSet, storeJunctionEntitySet, fromStoreAssocSet, toStoreAssocSet);

            _associationSetMappings.Add(asm.Name, asm);
            asm.NameChanged += new EventHandler <NameChangeArgs>(asm_NameChanged);
            asm.Removed     += new EventHandler(asm_Removed);
            return(asm);
        }
 void entitySet_Removed(object sender, EventArgs e)
 {
     _entitySet = null;
 }
 void StoreEntitySet_Removed(object sender, EventArgs e)
 {
     this.Remove();
     _storeEntitySet = null;
 }
Beispiel #25
0
        private void EnumerateMemberMappings()
        {
            foreach (XmlElement sp in _esmElement.SelectNodes("map:EntityTypeMapping/map:MappingFragment/map:ScalarProperty", NSM))
            {
                string modelPropertyName = sp.GetAttribute("Name");
                string entityTypeName    = EDMXUtils.StripTypeOf(((XmlElement)sp.ParentNode.ParentNode).GetAttribute("TypeName"));

                ModelEntityType     entityType = ParentFile.ConceptualModel.EntityTypes.FirstOrDefault(et => et.FullName == entityTypeName || et.AliasName == entityTypeName);
                ModelMemberProperty mmp        = entityType.MemberProperties.FirstOrDefault(mp => mp.Name == modelPropertyName);

                if (mmp != null)
                {
                    string         storeEntitySetName = ((XmlElement)sp.ParentNode).GetAttribute("StoreEntitySet");
                    StoreEntitySet ses = ParentFile.StorageModel.EntitySets.FirstOrDefault(es => es.Name.Equals(storeEntitySetName, StringComparison.InvariantCultureIgnoreCase));

                    if (ses != null)
                    {
                        string storePropertyName = sp.GetAttribute("ColumnName");
                        StoreMemberProperty smp  = ses.EntityType.MemberProperties.FirstOrDefault(mp => mp.Name.Equals(storePropertyName, StringComparison.InvariantCultureIgnoreCase));

                        if (smp != null)
                        {
                            _memberMappings.Add(new Tuple <StoreMemberProperty, ModelMemberProperty, ModelEntityType>(smp, mmp, entityType));

                            smp.Removed += new EventHandler(smp_Removed);
                            mmp.Removed += new EventHandler(mmp_Removed);
                        }
                    }
                }
            }
            foreach (XmlElement sp in _esmElement.SelectNodes("map:EntityTypeMapping/map:MappingFragment/map:ComplexProperty/map:ScalarProperty", NSM))
            {
                string modelPropertyName = sp.GetAttribute("Name");

                string           complexTypeName = EDMXUtils.StripTypeOf(((XmlElement)sp.ParentNode).GetAttribute("TypeName"));
                ModelComplexType complexType     = ParentFile.ConceptualModel.ComplexTypes.FirstOrDefault(ct => ct.FullName == complexTypeName || ct.AliasName == complexTypeName);

                string          entityTypeName = EDMXUtils.StripTypeOf(((XmlElement)sp.ParentNode.ParentNode.ParentNode).GetAttribute("TypeName"));
                ModelEntityType entityType     = ParentFile.ConceptualModel.EntityTypes.FirstOrDefault(et => et.FullName == entityTypeName || et.AliasName == entityTypeName);

                ModelMemberProperty mmp = null;
                if (complexType != null)
                {
                    mmp = complexType.MemberProperties.FirstOrDefault(mp => mp.Name == modelPropertyName);

                    if (mmp != null)
                    {
                        string         storeEntitySetName = ((XmlElement)sp.ParentNode.ParentNode).GetAttribute("StoreEntitySet");
                        StoreEntitySet ses = ParentFile.StorageModel.EntitySets.FirstOrDefault(es => es.Name.Equals(storeEntitySetName, StringComparison.InvariantCultureIgnoreCase));

                        if (ses != null)
                        {
                            string storePropertyName = sp.GetAttribute("ColumnName");
                            StoreMemberProperty smp  = ses.EntityType.MemberProperties.FirstOrDefault(mp => mp.Name.Equals(storePropertyName, StringComparison.InvariantCultureIgnoreCase));

                            if (smp != null)
                            {
                                _memberMappings.Add(new Tuple <StoreMemberProperty, ModelMemberProperty, ModelEntityType>(smp, mmp, entityType));

                                smp.Removed += new EventHandler(smp_Removed);
                                mmp.Removed += new EventHandler(mmp_Removed);
                            }
                        }
                    }
                }
            }
            _memberMappingsEnumerated = true;
        }
Beispiel #26
0
 void StoreEntitySetJunction_Removed(object sender, EventArgs e)
 {
     _storeEntitySetJunction = null;
 }
 void fromEntitySet_Removed(object sender, EventArgs e)
 {
     _fromEntitySet = null;
 }
 void StoreEntitySet_Removed(object sender, EventArgs e)
 {
     this.Remove();
     _storeEntitySet = null;
 }
 void entitySet_Removed(object sender, EventArgs e)
 {
     _entitySet = null;
 }
        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;
        }
 void StoreEntitySetJunction_Removed(object sender, EventArgs e)
 {
     _storeEntitySetJunction = null;
 }