private static XDocument CreateModel(Version targetSchemaVersion)
        {
            const string edmxTemplate =
                @"<!-- edmx -->
<edmx:Edmx Version=""{0}"" xmlns:edmx=""{1}"">
  <edmx:Runtime>
    <edmx:StorageModels>
      <Schema xmlns=""{2}"" />
    </edmx:StorageModels>
    <edmx:ConceptualModels>
      <Schema xmlns=""{3}"" />
    </edmx:ConceptualModels>
    <!-- C-S mapping content -->
    <edmx:Mappings>
      <Mapping xmlns=""{4}"" />
    </edmx:Mappings>
  </edmx:Runtime>
</edmx:Edmx>";

            return
                (XDocument.Parse(
                     string.Format(
                         edmxTemplate,
                         targetSchemaVersion.ToString(2),
                         SchemaManager.GetEDMXNamespaceName(targetSchemaVersion),
                         SchemaManager.GetCSDLNamespaceName(targetSchemaVersion),
                         SchemaManager.GetSSDLNamespaceName(targetSchemaVersion),
                         SchemaManager.GetMSLNamespaceName(targetSchemaVersion))));
        }
示例#2
0
        private static XmlDocument CreateSourceEdmx(Version schemaVersion)
        {
            const string template =
                "<Edmx xmlns=\"{0}\">" +
                "  <Runtime>" +
                "    <StorageModels>" +
                "      <Schema xmlns=\"{1}\" />" +
                "    </StorageModels>" +
                "    <ConceptualModels>" +
                "      <Schema xmlns=\"{2}\" />" +
                "    </ConceptualModels>" +
                "    <Mappings>" +
                "      <Mapping xmlns=\"{3}\" />" +
                "    </Mappings>" +
                "  </Runtime>" +
                "  <Designer/>" +
                "</Edmx>";

            var edmx = new XmlDocument();

            edmx.LoadXml(
                string.Format(
                    template,
                    SchemaManager.GetEDMXNamespaceName(schemaVersion),
                    SchemaManager.GetSSDLNamespaceName(schemaVersion),
                    SchemaManager.GetCSDLNamespaceName(schemaVersion),
                    SchemaManager.GetMSLNamespaceName(schemaVersion)));

            return(edmx);
        }
        private static LegacyMetadata.EdmItemCollection GetLegacyEdmItemCollection(Version version)
        {
            const string csdlTemplate =
                @"<Schema xmlns=""{0}"" Namespace=""dummy"">" +
                @"    <EntityContainer Name=""DummyContainer""/>" +
                @"</Schema>";

            LegacyMetadata.EdmItemCollection itemCollection;

            if (!LegacyEdmItemCollections.TryGetValue(version, out itemCollection))
            {
                var csdl = string.Format(CultureInfo.InvariantCulture,
                                         csdlTemplate, SchemaManager.GetCSDLNamespaceName(version));

                using (var stringReader = new StringReader(csdl))
                {
                    using (var reader = XmlReader.Create(stringReader))
                    {
                        itemCollection = new LegacyMetadata.EdmItemCollection(new[] { reader });
                        LegacyEdmItemCollections[version] = itemCollection;
                    }
                }
            }

            return(itemCollection);
        }
        /// <summary>
        ///     this will always return the preceding sibling that appears before the first sibling with a different namespace.
        /// </summary>
        /// <param name="parent"></param>
        /// <returns></returns>
        private static XElement GetLastSiblingOfMyNamespace(EFElement parent)
        {
            string expectedNamespace;

            if (ModelHelper.GetBaseModelRoot(parent).IsCSDL)
            {
                expectedNamespace = SchemaManager.GetCSDLNamespaceName(parent.Artifact.SchemaVersion);
            }
            else
            {
                expectedNamespace = SchemaManager.GetSSDLNamespaceName(parent.Artifact.SchemaVersion);
            }

            var      c          = parent.XContainer;
            XElement predecesor = null;

            foreach (var e in c.Elements())
            {
                if (e.Name.NamespaceName.Equals(expectedNamespace, StringComparison.OrdinalIgnoreCase))
                {
                    predecesor = e;
                }
                else
                {
                    break;
                }
            }
            return(predecesor);
        }
示例#5
0
 internal virtual void DetermineIfArtifactIsVersionSafe()
 {
     // make sure that the XML namespace of the EDMX, Csdl, ssdl & msl nodes match the expected XML namespaces for the schema version
     _isVersionSafe = GetRootNamespace() == SchemaManager.GetEDMXNamespaceName(SchemaVersion) &&
                      CompareNamespaces(ConceptualModel, SchemaManager.GetCSDLNamespaceName(SchemaVersion)) &&
                      CompareNamespaces(StorageModel, SchemaManager.GetSSDLNamespaceName(SchemaVersion)) &&
                      CompareNamespaces(MappingModel, SchemaManager.GetMSLNamespaceName(SchemaVersion));
 }
示例#6
0
        private static EntityDesignArtifact SetupArtifact(
            Version edmxVersion, Version storeModelVersion, Version conceptualModelVersion, Version mappingModelVersion)
        {
            var modelManager             = new Mock <ModelManager>(null, null).Object;
            var modelProvider            = new Mock <XmlModelProvider>().Object;
            var mockEntityDesignArtifact =
                new Mock <EntityDesignArtifact>(modelManager, new Uri("urn:dummy"), modelProvider)
            {
                CallBase = true
            };

            var mockConceptualModel =
                new Mock <ConceptualEntityModel>(
                    mockEntityDesignArtifact.Object,
                    new XElement(XName.Get("Schema", SchemaManager.GetCSDLNamespaceName(conceptualModelVersion))));

            mockConceptualModel
            .Setup(m => m.XNamespace)
            .Returns(SchemaManager.GetCSDLNamespaceName(conceptualModelVersion));

            mockEntityDesignArtifact
            .Setup(m => m.ConceptualModel)
            .Returns(mockConceptualModel.Object);

            var mockStoreModel =
                new Mock <StorageEntityModel>(
                    mockEntityDesignArtifact.Object,
                    new XElement(XName.Get("Schema", SchemaManager.GetSSDLNamespaceName(storeModelVersion))));

            mockStoreModel
            .Setup(m => m.XNamespace)
            .Returns(SchemaManager.GetSSDLNamespaceName(storeModelVersion));

            mockEntityDesignArtifact
            .Setup(m => m.StorageModel)
            .Returns(mockStoreModel.Object);

            var mockMappingModel =
                new Mock <MappingModel>(
                    mockEntityDesignArtifact.Object,
                    new XElement(XName.Get("Mapping", SchemaManager.GetMSLNamespaceName(mappingModelVersion))));

            mockMappingModel
            .Setup(m => m.XNamespace)
            .Returns(SchemaManager.GetMSLNamespaceName(mappingModelVersion));

            mockEntityDesignArtifact
            .Setup(m => m.MappingModel)
            .Returns(mockMappingModel.Object);

            mockEntityDesignArtifact
            .Setup(a => a.XDocument)
            .Returns(
                new XDocument(
                    new XElement(XName.Get("Edmx", SchemaManager.GetEDMXNamespaceName(edmxVersion)))));

            return(mockEntityDesignArtifact.Object);
        }
        protected override void DoParse(ICollection <XName> unprocessedElements)
        {
            // Ensure to parse all enum types before ConceptualProperty/ComplexConceptualProperty are parsed.
            // This is done so that we have enough information to decide which property to create.
            var csdlNamespaceName = SchemaManager.GetCSDLNamespaceName(Artifact.SchemaVersion);

            foreach (var element in XElement.Elements(XName.Get(EnumType.ElementName, csdlNamespaceName)))
            {
                var enumType = new EnumType(this, element);
                _enumTypes.Add(enumType);
                enumType.Parse(unprocessedElements);
            }

            base.DoParse(unprocessedElements);
        }
        internal NamespaceConverterHandler(Version sourceSchemaVersion, Version targetSchemaVersion)
        {
            var template = String.Format(
                CultureInfo.InvariantCulture, XsltTemplate,
                SchemaManager.GetEDMXNamespaceName(sourceSchemaVersion), SchemaManager.GetEDMXNamespaceName(targetSchemaVersion),
                SchemaManager.GetCSDLNamespaceName(sourceSchemaVersion), SchemaManager.GetCSDLNamespaceName(targetSchemaVersion),
                SchemaManager.GetSSDLNamespaceName(sourceSchemaVersion), SchemaManager.GetSSDLNamespaceName(targetSchemaVersion),
                SchemaManager.GetMSLNamespaceName(sourceSchemaVersion), SchemaManager.GetMSLNamespaceName(targetSchemaVersion));

            _xsltTransform = new XslCompiledTransform();

            using (var reader = XmlReader.Create(new StringReader(template)))
            {
                _xsltTransform.Load(reader);
            }
        }
示例#9
0
        public void UpdateConceptualModel_updates_csdl()
        {
            var edmx = XDocument.Parse(EdmxTemplate);

            new EdmxHelper(edmx)
            .UpdateConceptualModels(new EdmModel(DataSpace.CSpace), "modelNamespace");

            var conceptualModelsElements =
                edmx.Descendants(EdmxV3Namespace + "ConceptualModels").Single();

            Assert.Equal(1, conceptualModelsElements.Elements().Count());
            Assert.Equal(
                XName.Get("Schema", SchemaManager.GetCSDLNamespaceName(EntityFrameworkVersion.Version3)),
                conceptualModelsElements.Elements().Single().Name);

            Assert.Equal("modelNamespace", (string)conceptualModelsElements.Elements().Single().Attribute("Namespace"));
        }
示例#10
0
        public void DetermineIfArtifactIsVersionSafe_sets_IsVersionSafe_to_false_if_versions_dont_match()
        {
            var mockDte = new MockDTE(
                ".NETFramework, Version=v4.5.1",
                Constants.vsMiscFilesProjectUniqueName);

            var modelManager   = new Mock <ModelManager>(null, null).Object;
            var modelProvider  = new Mock <XmlModelProvider>().Object;
            var mockVsArtifact =
                new Mock <VSArtifact>(modelManager, new Uri("urn:dummy"), modelProvider)
            {
                CallBase = true
            };

            mockVsArtifact.Protected().Setup <IServiceProvider>("ServiceProvider").Returns(mockDte.ServiceProvider);
            mockVsArtifact.Protected().Setup <Project>("GetProject").Returns(mockDte.Project);
            mockVsArtifact.Setup(a => a.XDocument).Returns(
                new XDocument(
                    new XElement(
                        XName.Get(
                            "Edmx",
                            SchemaManager.GetEDMXNamespaceName(EntityFrameworkVersion.Version3)))));

            var mockConceptualModel =
                new Mock <ConceptualEntityModel>(
                    mockVsArtifact.Object,
                    new XElement(XName.Get("Schema", SchemaManager.GetCSDLNamespaceName(EntityFrameworkVersion.Version2))));

            mockConceptualModel
            .Setup(m => m.XNamespace)
            .Returns(SchemaManager.GetCSDLNamespaceName(EntityFrameworkVersion.Version2));

            mockVsArtifact
            .Setup(m => m.ConceptualModel)
            .Returns(mockConceptualModel.Object);

            var artifact = mockVsArtifact.Object;

            artifact.DetermineIfArtifactIsVersionSafe();
            Assert.False(artifact.IsVersionSafe);
        }
        private static EntityType CreateEntityType <T>() where T : EntityType
        {
            XNamespace ns = typeof(T) == typeof(ConceptualEntityType)
                                ? SchemaManager.GetCSDLNamespaceName(EntityFrameworkVersion.Version3)
                                : SchemaManager.GetSSDLNamespaceName(EntityFrameworkVersion.Version3);

            var mockModelProvider = new Mock <XmlModelProvider>();
            var mockModelManager  =
                new Mock <ModelManager>(new Mock <IEFArtifactFactory>().Object, new Mock <IEFArtifactSetFactory>().Object);

            mockModelManager.Setup(m => m.GetRootNamespace(It.IsAny <EFObject>())).Returns(ns);

            var mockValidator = new Mock <AttributeContentValidator>(null);

            mockModelManager.Setup(m => m.GetAttributeContentValidator(It.IsAny <EFArtifact>()))
            .Returns(mockValidator.Object);

            var mockArtifact    = new Mock <EntityDesignArtifact>(mockModelManager.Object, new Uri("http://tempuri"), mockModelProvider.Object);
            var mockArtifactSet = new Mock <EFArtifactSet>(mockArtifact.Object)
            {
                CallBase = true
            };

            mockArtifact.Setup(m => m.SchemaVersion).Returns(EntityFrameworkVersion.Version3);
            mockArtifact.Setup(m => m.ArtifactSet).Returns(mockArtifactSet.Object);
            mockModelManager.Setup(m => m.GetArtifactSet(It.IsAny <Uri>())).Returns(mockArtifactSet.Object);

            var mockEntity = new Mock <T>(null, new XElement(ns + "EntityType"))
            {
                CallBase = true
            };

            mockEntity.Setup(e => e.Parent).Returns(mockArtifact.Object);
            mockEntity.Setup(e => e.Artifact).Returns(mockArtifact.Object);

            return(mockEntity.Object);
        }
        public void ToLegacyMetadataWorkspace_creates_equivalent_legacy_MetadataWorkspace_for_all_versions()
        {
            const string ssdlTemplate =
                @"<Schema Namespace=""NorthwindEF5Model.Store"" Provider=""System.Data.SqlClient"" ProviderManifestToken=""2008"" Alias=""Self"" xmlns=""{0}"" xmlns:store=""http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator"">"
                +
                @"  <EntityType Name=""Customers"">" +
                @"    <Key>" +
                @"      <PropertyRef Name=""CustomerID"" />" +
                @"    </Key>" +
                @"    <Property Name=""CustomerID"" Type=""nchar"" MaxLength=""5"" Nullable=""false"" />" +
                @"    <Property Name=""CompanyName"" Type=""nvarchar"" MaxLength=""40"" Nullable=""false"" />" +
                @"  </EntityType>" +
                @"  <EntityContainer Name=""Container"" />" +
                @"</Schema>";

            const string csdlTemplate =
                @"<Schema xmlns=""{0}"" Namespace=""dummy"">" +
                @"    <EntityContainer Name=""DummyContainer""/>" +
                @"</Schema>";

            const string mslTemplate =
                @"<Mapping Space=""C-S"" xmlns=""{0}"">" +
                @"  <EntityContainerMapping StorageEntityContainer=""Container"" CdmEntityContainer=""DummyContainer"" />" +
                @"</Mapping>";

            foreach (var version in EntityFrameworkVersion.GetAllVersions())
            {
                var storeItemCollection =
                    Utils.CreateStoreItemCollection(
                        string.Format(
                            ssdlTemplate,
                            SchemaManager.GetSSDLNamespaceName(version)));
                var edmItemCollection =
                    new EdmItemCollection(
                        new[]
                {
                    XmlReader.Create(
                        new StringReader(
                            string.Format(
                                csdlTemplate,
                                SchemaManager.GetCSDLNamespaceName(version))))
                });
                var mappingItemCollection =
                    new StorageMappingItemCollection(
                        edmItemCollection,
                        storeItemCollection,
                        new[]
                {
                    XmlReader.Create(
                        new StringReader(
                            string.Format(
                                mslTemplate,
                                SchemaManager.GetMSLNamespaceName(version))))
                });
                var workspace = new MetadataWorkspace(
                    () => edmItemCollection,
                    () => storeItemCollection,
                    () => mappingItemCollection);

                var legacyWorkspace = workspace.ToLegacyMetadataWorkspace();

                Assert.NotNull(legacyWorkspace);

                var legacyStoreItemCollection = legacyWorkspace.GetItemCollection(LegacyMetadata.DataSpace.SSpace);

                Assert.Equal(
                    storeItemCollection.GetItems <GlobalItem>().Count,
                    legacyStoreItemCollection.GetItems <LegacyMetadata.GlobalItem>().Count);

                Assert.NotNull(
                    legacyStoreItemCollection.GetItem <LegacyMetadata.EntityType>("NorthwindEF5Model.Store.Customers"));

                var legacyEdmItemCollection =
                    (LegacyMetadata.EdmItemCollection)legacyWorkspace.GetItemCollection(LegacyMetadata.DataSpace.CSpace);
                Assert.NotNull(legacyEdmItemCollection);
                Assert.Equal(version, EntityFrameworkVersion.DoubleToVersion(legacyEdmItemCollection.EdmVersion));

                Assert.NotNull(legacyWorkspace.GetItemCollection(LegacyMetadata.DataSpace.CSSpace));
            }
        }
        public static void AddSchemaSpecificReplacements(IDictionary <string, string> replacementsDictionary, Version schemaVersion)
        {
            Debug.Assert(replacementsDictionary != null, "replacementsDictionary is null.");
            Debug.Assert(schemaVersion != null, "schemaVersion is null.");
            Debug.Assert(!replacementsDictionary.ContainsKey("$edmxversion$"), "replacementsDictionary contains key '$edmxversion$'");
            Debug.Assert(
                !replacementsDictionary.ContainsKey("$edmxnamespacename$"), "replacementsDictionary contains key '$edmxnamespacename$'");
            Debug.Assert(
                !replacementsDictionary.ContainsKey("$ssdlnamespacename$"), "replacementsDictionary contains key '$ssdlnamespacename$'");
            Debug.Assert(
                !replacementsDictionary.ContainsKey("$csdlnamespacename$"), "replacementsDictionary contains key '$csdlnamespacename$'");
            Debug.Assert(
                !replacementsDictionary.ContainsKey("$msdlnamespacename$"), "replacementsDictionary contains key '$msdlnamespacename$'");
            Debug.Assert(
                !replacementsDictionary.ContainsKey("$essgnamespacename$"), "replacementsDictionary contains key '$essgnamespacename$'");
            Debug.Assert(
                !replacementsDictionary.ContainsKey("$cgnamespacename$"), "replacementsDictionary contains key '$cgnamespacename$'");
            Debug.Assert(
                !replacementsDictionary.ContainsKey("$annotationnamespace$"), "replacementsDictionary contains key '$annotationnamespace$'");
            Debug.Assert(
                !replacementsDictionary.ContainsKey("$lazyloadingattribute$"),
                "replacementsDictionary contains key '$lazyloadingattribute$'");
            Debug.Assert(
                !replacementsDictionary.ContainsKey("$useStrongSpatialTypesAttribute$"),
                "replacementsDictionary contains key '$useStrongSpatialTypesAttribute$'");

            // Set the namespace names (EDMX, CodeGen, ESSG, CSDL, MSDL, and SSDL)
            replacementsDictionary.Add("$edmxversion$", schemaVersion.ToString(2)); // only print Major.Minor version information
            replacementsDictionary.Add("$edmxnamespacename$", SchemaManager.GetEDMXNamespaceName(schemaVersion));
            replacementsDictionary.Add("$ssdlnamespacename$", SchemaManager.GetSSDLNamespaceName(schemaVersion));
            replacementsDictionary.Add("$csdlnamespacename$", SchemaManager.GetCSDLNamespaceName(schemaVersion));
            replacementsDictionary.Add("$msdlnamespacename$", SchemaManager.GetMSLNamespaceName(schemaVersion));
            replacementsDictionary.Add(
                "$essgnamespacename$",
                SchemaManager.GetEntityStoreSchemaGeneratorNamespaceName());
            replacementsDictionary.Add(
                "$cgnamespacename$",
                SchemaManager.GetCodeGenerationNamespaceName());

            if (EdmFeatureManager.GetLazyLoadingFeatureState(schemaVersion).IsEnabled() ||
                EdmFeatureManager.GetUseStrongSpatialTypesFeatureState(schemaVersion).IsEnabled())
            {
                replacementsDictionary.Add(
                    "$annotationnamespace$",
                    string.Format(
                        CultureInfo.InvariantCulture,
                        "xmlns:annotation=\"{0}\"",
                        SchemaManager.GetAnnotationNamespaceName()));
            }
            else
            {
                replacementsDictionary.Add("$annotationnamespace$", string.Empty);
            }

            if (EdmFeatureManager.GetLazyLoadingFeatureState(schemaVersion).IsEnabled())
            {
                replacementsDictionary.Add("$lazyloadingattribute$", "annotation:LazyLoadingEnabled=\"true\"");
            }
            else
            {
                replacementsDictionary.Add("$lazyloadingattribute$", string.Empty);
            }

            // set UseStrongSpatialTypes to false as runtime will throw exception if true (as of V3 - to be updated in later version of runtime)
            if (EdmFeatureManager.GetUseStrongSpatialTypesFeatureState(schemaVersion).IsEnabled())
            {
                replacementsDictionary.Add(
                    "$useStrongSpatialTypesAttribute$",
                    "annotation:UseStrongSpatialTypes=\"false\"");
            }
            else
            {
                replacementsDictionary.Add("$useStrongSpatialTypesAttribute$", string.Empty);
            }
        }
        protected override void InvokeInternal(CommandProcessorContext cpc)
        {
            Debug.Assert(
                PrincipalEnd != null && DependentEnd != null, "InvokeInternal is called when PrincipalEnd or DependentEnd is null.");
            if (PrincipalEnd == null ||
                DependentEnd == null)
            {
                throw new InvalidOperationException("InvokeInternal is called when PrincipalEnd or DependentEnd is null.");
            }

            var association = PrincipalEnd.Parent as Association;

            Debug.Assert(
                association != null && association == DependentEnd.Parent, "Association parent for both ends must agree and be not null");

            var principalProps = PrincipalProperties.ToList();
            var dependentProps = DependentProperties.ToList();

            Debug.Assert(principalProps.Count == dependentProps.Count, "Number of principal and dependent properties must agree");
            Debug.Assert(principalProps.Count > 0, "Number of properties must be positive");

            var referentialConstraint = new ReferentialConstraint(association, null);

            association.ReferentialConstraint = referentialConstraint;
            XmlModelHelper.NormalizeAndResolve(referentialConstraint);

            var principalRole = new ReferentialConstraintRole(referentialConstraint, null);
            var dependentRole = new ReferentialConstraintRole(referentialConstraint, null);

            var service = cpc.EditingContext.GetEFArtifactService();

            // we can't pass the type of referential constraint role ("Principal" or "Dependent")
            // in the constructor because XElement gets created in base constructor
            // before we have a chance to set any properties
            if (association.EntityModel.IsCSDL)
            {
                var csdlNamespaceName = SchemaManager.GetCSDLNamespaceName(service.Artifact.SchemaVersion);
                principalRole.XElement.Name = XName.Get(ReferentialConstraint.ElementNamePrincipal, csdlNamespaceName);
                dependentRole.XElement.Name = XName.Get(ReferentialConstraint.ElementNameDependent, csdlNamespaceName);
            }
            else
            {
                var ssdlNamespaceName = SchemaManager.GetSSDLNamespaceName(service.Artifact.SchemaVersion);
                principalRole.XElement.Name = XName.Get(ReferentialConstraint.ElementNamePrincipal, ssdlNamespaceName);
                dependentRole.XElement.Name = XName.Get(ReferentialConstraint.ElementNameDependent, ssdlNamespaceName);
            }

            principalRole.Role.SetRefName(PrincipalEnd);
            dependentRole.Role.SetRefName(DependentEnd);

            referentialConstraint.Principal = principalRole;
            referentialConstraint.Dependent = dependentRole;

            XmlModelHelper.NormalizeAndResolve(principalRole);
            XmlModelHelper.NormalizeAndResolve(dependentRole);

            for (var i = 0; i < principalProps.Count; i++)
            {
                principalRole.AddPropertyRef(principalProps[i]);
                dependentRole.AddPropertyRef(dependentProps[i]);
            }

            Debug.Assert(
                principalProps.Count == 0 ||
                (principalRole.PropertyRefs.First().Name.Target != null && dependentRole.PropertyRefs.First().Name.Target != null),
                "Unresolved property references");

            _createdRefConstraint = referentialConstraint;
        }
示例#15
0
        /// <summary>
        ///     Move Property's XElement before the specified position.
        ///     If position parameter is null, the property XElement will be moved to the last position.
        /// </summary>
        internal void MoveTo(InsertPropertyPosition position)
        {
            Debug.Assert(
                PreviousSiblingInPropertyXElementOrder != null || NextSiblingInPropertyXElementOrder != null,
                "Why do we need to move the property if it is the only property?");
            Debug.Assert(position != null, "InsertPropertyPosition parameter is null.");
            if (position != null)
            {
                // Check if the InsertPropertyPosition's InsertAt is not null.
                Debug.Assert(position.InsertAtProperty != null, "Why InsertPropertyPosition's InsertAt is null?");
                if (position.InsertAtProperty != null)
                {
                    // Instead of re-parenting the property's XElement, we are going to clone the XElement, insert the clone and delete the old XElement.
                    // This is a workaround for 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 newPropertyXElement = tempDoc.Root;
                    newPropertyXElement.Remove();

                    // Remove known namespaces from the element since the namespaces are already set in the parent node.
                    // This is workaround because XDocument automatically appends the default namespace in the property XElement.
                    foreach (var a in newPropertyXElement.Attributes())
                    {
                        if (a.IsNamespaceDeclaration &&
                            (a.Value == SchemaManager.GetCSDLNamespaceName(Artifact.SchemaVersion) ||
                             a.Value == SchemaManager.GetSSDLNamespaceName(Artifact.SchemaVersion) ||
                             a.Value == SchemaManager.GetAnnotationNamespaceName()))
                        {
                            a.Remove();
                        }
                    }

                    var toBeDeleteElement = XElement;

                    // format the XML we just parsed so that the XElement will have the same indenting.
                    Utils.FormatXML(newPropertyXElement, GetIndentLevel());

                    // Call method that will insert the XElement to the specified location.
                    InsertPosition = position;
                    AddXElementToParent(newPropertyXElement);

                    // Re-establish the links between EFElement and XElement.
                    SetXObject(newPropertyXElement);
                    Debug.Assert(
                        XElement == newPropertyXElement,
                        "Unexpected XElement value. Expected:" + newPropertyXElement + " , Actual:" + XElement);

                    ModelItemAnnotation.SetModelItem(newPropertyXElement, this);
                    Debug.Assert(
                        ModelItemAnnotation.GetModelItem(newPropertyXElement) == this,
                        "The new XElement should contain annotation to the model property.");

                    // Delete both old XElement and the preceding whitespace.
                    // Preceding whitespace is preferred over trailing whitespace because we don't want to remove the last property's trailing white-space since
                    // it has different indent level than the rest (see EFElement's EnsureFirstNodeWhitespaceSeparation method).
                    var preceedingNewLine = toBeDeleteElement.PreviousNode as XText;
                    while (preceedingNewLine != null &&
                           String.IsNullOrWhiteSpace(preceedingNewLine.Value))
                    {
                        var toBeDeletedWhiteSpace = preceedingNewLine;
                        preceedingNewLine = preceedingNewLine.PreviousNode as XText;
                        toBeDeletedWhiteSpace.Remove();
                    }
                    toBeDeleteElement.Remove();

#if DEBUG
                    // Assert if the property is not moved to the correct location.
                    if (position.InsertBefore)
                    {
                        Debug.Assert(
                            position.InsertAtProperty == NextSiblingInPropertyXElementOrder,
                            "Expected next sibling property: " + position.InsertAtProperty.DisplayName + " , Actual next sibling:"
                            + NextSiblingInPropertyXElementOrder.DisplayName);
                    }
                    else
                    {
                        Debug.Assert(
                            position.InsertAtProperty == PreviousSiblingInPropertyXElementOrder,
                            "Expected previous sibling property: " + position.InsertAtProperty.DisplayName + " , Actual previous sibling:"
                            + PreviousSiblingInPropertyXElementOrder.DisplayName);
                    }
#endif
                }
            }
        }