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;
        }
Exemplo n.º 2
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 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;
        }
Exemplo n.º 4
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;
 }
Exemplo n.º 5
0
 void StoreAssociationSet_Removed(object sender, EventArgs e)
 {
     _storeAssociationSet = null;
 }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
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.");
     }
 }
 void StoreAssociationSet_Removed(object sender, EventArgs e)
 {
     _storeAssociationSet = null;
 }