Example #1
0
        protected override void DoParse(ICollection <XName> unprocessedElements)
        {
            // call base DoParse first
            base.DoParse(unprocessedElements);

            // now see if this has an attribute called "TypeName"
            if (GetAttributeValue(EntityTypeMapping.AttributeTypeName) != null)
            {
                if (_entityTypeMappings.Count == 0)
                {
                    // TypeName attribute and no EntityTypeMapping children.  Create a "ghost-node".
                    var etm = new EntityTypeMapping(this, XElement);
                    _entityTypeMappings.Add(etm);
                    etm.Parse(unprocessedElements);

                    // Add an error - we don't want to support this syntax in the designer.
                    var msg = String.Format(
                        CultureInfo.CurrentCulture, Resources.ModelParse_GhostNodeNotSupportedByDesigner,
                        EntityTypeMapping.AttributeTypeName, ElementName);
                    Artifact.AddParseErrorForObject(this, msg, ErrorCodes.ModelParse_GhostNodeNotSupportedByDesigner);
                }
                else
                {
                    // TypeName attribute and EntityTypeMapping children.  These are mutually exclusive.
                    var msg = String.Format(
                        CultureInfo.CurrentCulture, Resources.ModelParse_MutuallyExclusiveAttributeAndChildElement,
                        EntityTypeMapping.AttributeTypeName, EntityTypeMapping.ElementName);
                    Artifact.AddParseErrorForObject(this, msg, ErrorCodes.ModelParse_MutuallyExclusiveAttributeAndChildElement);
                }
            }
        }
Example #2
0
        internal EntityTypeMapping Clone(EntitySetMapping newEntitySetMapping)
        {
            // here we clone the entity type mapping, instead of re-parenting it
            // this works around an XML editor bug where re-parenting an element causes asserts

            // first create the new XElement
            var tempDoc        = XDocument.Parse(XElement.ToString(SaveOptions.None), LoadOptions.None);
            var newetmXElement = tempDoc.Root;

            newetmXElement.Remove();
            // format the XML we just parsed
            Utils.FormatXML(newetmXElement, newEntitySetMapping.GetIndentLevel() + 1);

            // create the EntityTypeMapping & hook in it's xml.
            var newetm = new EntityTypeMapping(newEntitySetMapping, newetmXElement);

            newetm.AddXElementToParent(newetmXElement);

            // parse & Resolve the new EntityTypeMapping
            newetm.Parse(new HashSet <XName>());
            XmlModelHelper.NormalizeAndResolve(newetm);

            // add it to new EntitySetMapping
            newEntitySetMapping.AddEntityTypeMapping(newetm);

            return(newetm);
        }
Example #3
0
 internal override bool ParseSingleElement(ICollection <XName> unprocessedElements, XElement elem)
 {
     if (elem.Name.LocalName == EntityTypeMapping.ElementName)
     {
         var etm = new EntityTypeMapping(this, elem);
         _entityTypeMappings.Add(etm);
         etm.Parse(unprocessedElements);
     }
     else if (elem.Name.LocalName == QueryView.ElementName)
     {
         var qv = new QueryView(this, elem);
         qv.Parse(unprocessedElements);
         _queryViews.Add(qv);
     }
     else
     {
         return(base.ParseSingleElement(unprocessedElements, elem));
     }
     return(true);
 }
 internal override bool ParseSingleElement(ICollection<XName> unprocessedElements, XElement elem)
 {
     if (elem.Name.LocalName == EntityTypeMapping.ElementName)
     {
         var etm = new EntityTypeMapping(this, elem);
         _entityTypeMappings.Add(etm);
         etm.Parse(unprocessedElements);
     }
     else if (elem.Name.LocalName == QueryView.ElementName)
     {
         var qv = new QueryView(this, elem);
         qv.Parse(unprocessedElements);
         _queryViews.Add(qv);
     }
     else
     {
         return base.ParseSingleElement(unprocessedElements, elem);
     }
     return true;
 }
        protected override void DoParse(ICollection<XName> unprocessedElements)
        {
            // call base DoParse first
            base.DoParse(unprocessedElements);

            // now see if this has an attribute called "TypeName"
            if (GetAttributeValue(EntityTypeMapping.AttributeTypeName) != null)
            {
                if (_entityTypeMappings.Count == 0)
                {
                    // TypeName attribute and no EntityTypeMapping children.  Create a "ghost-node".
                    var etm = new EntityTypeMapping(this, XElement);
                    _entityTypeMappings.Add(etm);
                    etm.Parse(unprocessedElements);

                    // Add an error - we don't want to support this syntax in the designer.
                    var msg = String.Format(
                        CultureInfo.CurrentCulture, Resources.ModelParse_GhostNodeNotSupportedByDesigner,
                        EntityTypeMapping.AttributeTypeName, ElementName);
                    Artifact.AddParseErrorForObject(this, msg, ErrorCodes.ModelParse_GhostNodeNotSupportedByDesigner);
                }
                else
                {
                    // TypeName attribute and EntityTypeMapping children.  These are mutually exclusive.
                    var msg = String.Format(
                        CultureInfo.CurrentCulture, Resources.ModelParse_MutuallyExclusiveAttributeAndChildElement,
                        EntityTypeMapping.AttributeTypeName, EntityTypeMapping.ElementName);
                    Artifact.AddParseErrorForObject(this, msg, ErrorCodes.ModelParse_MutuallyExclusiveAttributeAndChildElement);
                }
            }
        }
        internal EntityTypeMapping Clone(EntitySetMapping newEntitySetMapping)
        {
            // here we clone the entity type mapping, instead of re-parenting it
            // this works around an XML editor bug where re-parenting an element causes asserts

            // first create the new XElement
            var tempDoc = XDocument.Parse(XElement.ToString(SaveOptions.None), LoadOptions.None);
            var newetmXElement = tempDoc.Root;
            newetmXElement.Remove();
            // format the XML we just parsed
            Utils.FormatXML(newetmXElement, newEntitySetMapping.GetIndentLevel() + 1);

            // create the EntityTypeMapping & hook in it's xml. 
            var newetm = new EntityTypeMapping(newEntitySetMapping, newetmXElement);
            newetm.AddXElementToParent(newetmXElement);

            // parse & Resolve the new EntityTypeMapping
            newetm.Parse(new HashSet<XName>());
            XmlModelHelper.NormalizeAndResolve(newetm);

            // add it to new EntitySetMapping
            newEntitySetMapping.AddEntityTypeMapping(newetm);

            return newetm;
        }