コード例 #1
0
 internal ModelMemberProperty(EDMXFile parentFile, ModelComplexType modelComplexType, XmlElement memberPropertyElement)
     : base(parentFile)
 {
     _modelComplexType = modelComplexType;
     _modelComplexType.Removed += new EventHandler(ModelComplexType_Removed);
     _propertyElement = memberPropertyElement;
 }
コード例 #2
0
 internal ModelMemberProperty(EDMXFile parentFile, ModelComplexType modelComplexType, XmlElement memberPropertyElement)
     : base(parentFile)
 {
     _modelComplexType          = modelComplexType;
     _modelComplexType.Removed += new EventHandler(ModelComplexType_Removed);
     _propertyElement           = memberPropertyElement;
 }
コード例 #3
0
 /// <summary>
 /// Creates and adds a new complex type to the conceptual model.
 /// </summary>
 /// <param name="name">Type name for the new complex type.</param>
 /// <returns>A ModelComplexType corresponding to the new complex type.</returns>
 public ModelComplexType AddComplexType(string name)
 {
     try
     {
         if (!EntityTypes.Any(et => et.Name == name) &&
             !ComplexTypes.Any(ct => ct.Name == name))
         {
             ModelComplexType ct = new ModelComplexType(ParentFile, this, name);
             _modelComplexTypes.Add(name, ct);
             ct.NameChanged += new EventHandler <NameChangeArgs>(ct_NameChanged);
             ct.Removed     += new EventHandler(ct_Removed);
             return(ct);
         }
         else
         {
             throw new ArgumentException("A type with the name " + name + " already exist 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;
     }
 }
コード例 #4
0
        internal ModelMemberProperty(EDMXFile parentFile, ModelComplexType modelComplexType, string name, XmlElement entityTypeElement)
            : base(parentFile)
        {
            _modelComplexType = modelComplexType;
            _modelComplexType.Removed += new EventHandler(ModelComplexType_Removed);

            _propertyElement = EDMXDocument.CreateElement("Property", NameSpaceURIcsdl);
            entityTypeElement.AppendChild(_propertyElement);

            Name = name;
        }
コード例 #5
0
        internal ModelMemberProperty(EDMXFile parentFile, ModelComplexType modelComplexType, string name, XmlElement entityTypeElement)
            : base(parentFile)
        {
            _modelComplexType          = modelComplexType;
            _modelComplexType.Removed += new EventHandler(ModelComplexType_Removed);

            _propertyElement = EDMXDocument.CreateElement("Property", NameSpaceURIcsdl);
            entityTypeElement.AppendChild(_propertyElement);

            Name = name;
        }
コード例 #6
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;
        }
コード例 #7
0
 /// <summary>
 /// Creates and adds a new complex type to the conceptual model.
 /// </summary>
 /// <param name="name">Type name for the new complex type.</param>
 /// <returns>A ModelComplexType corresponding to the new complex type.</returns>
 public ModelComplexType AddComplexType(string name)
 {
     try
     {
         if (!EntityTypes.Any(et => et.Name == name)
             && !ComplexTypes.Any(ct => ct.Name == name))
         {
             ModelComplexType ct = new ModelComplexType(ParentFile, this, name);
             _modelComplexTypes.Add(name, ct);
             ct.NameChanged += new EventHandler<NameChangeArgs>(ct_NameChanged);
             ct.Removed += new EventHandler(ct_Removed);
             return ct;
         }
         else
         {
             throw new ArgumentException("A type with the name " + name + " already exist 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;
     }
 }