protected virtual void Visit(StorageComplexPropertyMapping storageComplexPropertyMapping)
 {
     Visit(storageComplexPropertyMapping.EdmProperty);
     foreach (var mapping in GetSequence(storageComplexPropertyMapping.TypeMappings, it => IdentityHelper.GetIdentity(it)))
     {
         Visit(mapping);
     }
 }
 protected virtual void Visit(StorageComplexPropertyMapping storageComplexPropertyMapping)
 {
     Visit(storageComplexPropertyMapping.EdmProperty);
     foreach (var mapping in storageComplexPropertyMapping.TypeMappings)
     {
         Visit(mapping);
     }
 }
Пример #3
0
        public static void GetIdentity_of_StorageComplexPropertyMapping_returns_expected_value()
        {
            var complexType = new ComplexType("CT", "N", DataSpace.CSpace);
            var property    = new EdmProperty("A", TypeUsage.Create(complexType));
            StoragePropertyMapping mapping = new StorageComplexPropertyMapping(property);

            Assert.Equal("ComplexProperty(Identity=A)",
                         BaseMetadataMappingVisitor.IdentityHelper.GetIdentity(mapping));
        }
Пример #4
0
        protected override void Visit(StorageComplexPropertyMapping storageComplexPropertyMapping)
        {
            int index;

            if (!AddObjectToSeenListAndHashBuilder(storageComplexPropertyMapping, out index))
            {
                return;
            }

            AddObjectStartDumpToHashBuilder(storageComplexPropertyMapping, index);

            #region Inner data visit

            base.Visit(storageComplexPropertyMapping);

            #endregion

            AddObjectEndDumpToHashBuilder();
        }
Пример #5
0
        public static void GetIdentity_of_StorageComplexTypeMapping_returns_expected_value()
        {
            var complexType1     = new ComplexType("CT1", "N", DataSpace.CSpace);
            var complexType2     = new ComplexType("CT2", "N", DataSpace.CSpace);
            var complexType3     = new ComplexType("CT3", "N", DataSpace.CSpace);
            var complexType4     = new ComplexType("CT4", "N", DataSpace.CSpace);
            var property1        = new EdmProperty("A", TypeUsage.Create(complexType1));
            var property2        = new EdmProperty("B", TypeUsage.Create(complexType2));
            var propertyMapping1 = new StorageComplexPropertyMapping(property1);
            var propertyMapping2 = new StorageComplexPropertyMapping(property2);

            var mapping = new StorageComplexTypeMapping(false);

            mapping.AddType(complexType2);
            mapping.AddType(complexType1);
            mapping.AddIsOfType(complexType4);
            mapping.AddIsOfType(complexType3);
            mapping.AddProperty(propertyMapping2);
            mapping.AddProperty(propertyMapping1);

            Assert.Equal("ComplexProperty(Identity=A),ComplexProperty(Identity=B),N.CT1,N.CT2,N.CT3,N.CT4",
                         BaseMetadataMappingVisitor.IdentityHelper.GetIdentity(mapping));
        }
 protected virtual void Visit(StorageComplexPropertyMapping storageComplexPropertyMapping)
 {
     Visit(storageComplexPropertyMapping.EdmProperty);
     foreach (var mapping in storageComplexPropertyMapping.TypeMappings)
     {
         Visit(mapping);
     }
 }
        public void AddColumnMapping(ColumnMappingBuilder columnMappingBuilder)
        {
            Check.NotNull(columnMappingBuilder, "columnMappingBuilder");
            if (!columnMappingBuilder.PropertyPath.Any()
                || _columnMappings.Contains(columnMappingBuilder))
            {
                throw new ArgumentException(Strings.InvalidColumnBuilderArgument("columnBuilderMapping"));
            }

            DebugCheck.NotNull(columnMappingBuilder.ColumnProperty);

            _columnMappings.Add(columnMappingBuilder);

            StructuralTypeMapping structuralTypeMapping = this;
            EdmProperty property;

            // Turn the property path into a mapping fragment nested tree structure.

            var i = 0;
            for (; i < columnMappingBuilder.PropertyPath.Count - 1; i++)
            {
                // The first n-1 properties are complex so we just need to build
                // a corresponding tree of complex type mappings.

                property = columnMappingBuilder.PropertyPath[i];

                var complexPropertyMapping
                    = structuralTypeMapping
                        .Properties
                        .OfType<StorageComplexPropertyMapping>()
                        .SingleOrDefault(pm => ReferenceEquals(pm.EdmProperty, property));

                StorageComplexTypeMapping complexTypeMapping = null;

                if (complexPropertyMapping == null)
                {
                    complexTypeMapping = new StorageComplexTypeMapping(false);
                    complexTypeMapping.AddType(property.ComplexType);

                    complexPropertyMapping = new StorageComplexPropertyMapping(property);
                    complexPropertyMapping.AddTypeMapping(complexTypeMapping);

                    structuralTypeMapping.AddProperty(complexPropertyMapping);
                }

                structuralTypeMapping
                    = complexTypeMapping
                      ?? complexPropertyMapping.TypeMappings.Single();
            }

            // The last property has to be a scalar mapping to the target column.
            // Extract it and create the scalar mapping leaf node, ensuring that we 
            // set the target column.

            property = columnMappingBuilder.PropertyPath[i];

            var scalarPropertyMapping
                = structuralTypeMapping
                    .Properties
                    .OfType<StorageScalarPropertyMapping>()
                    .SingleOrDefault(pm => ReferenceEquals(pm.EdmProperty, property));

            if (scalarPropertyMapping == null)
            {
                scalarPropertyMapping
                    = new StorageScalarPropertyMapping(property, columnMappingBuilder.ColumnProperty);

                structuralTypeMapping.AddProperty(scalarPropertyMapping);

                columnMappingBuilder.SetTarget(scalarPropertyMapping);
            }
            else
            {
                scalarPropertyMapping.ColumnProperty = columnMappingBuilder.ColumnProperty;
            }
        }
Пример #8
0
        public void AddColumnMapping(ColumnMappingBuilder columnMappingBuilder)
        {
            DebugCheck.NotNull(columnMappingBuilder);
            DebugCheck.NotNull(columnMappingBuilder.ColumnProperty);
            Debug.Assert(columnMappingBuilder.PropertyPath.Any());
            Debug.Assert(!_columnMappings.Contains(columnMappingBuilder));

            _columnMappings.Add(columnMappingBuilder);

            IStructuralTypeMapping structuralTypeMapping = this;
            EdmProperty            property;

            // Turn the property path into a mapping fragment nested tree structure.

            var i = 0;

            for (; i < columnMappingBuilder.PropertyPath.Count - 1; i++)
            {
                // The first n-1 properties are complex so we just need to build
                // a corresponding tree of complex type mappings.

                property = columnMappingBuilder.PropertyPath[i];

                var complexPropertyMapping
                    = structuralTypeMapping
                      .Properties
                      .OfType <StorageComplexPropertyMapping>()
                      .SingleOrDefault(pm => ReferenceEquals(pm.EdmProperty, property));

                StorageComplexTypeMapping complexTypeMapping = null;

                if (complexPropertyMapping == null)
                {
                    complexTypeMapping = new StorageComplexTypeMapping(false);
                    complexTypeMapping.AddType(property.ComplexType);

                    complexPropertyMapping = new StorageComplexPropertyMapping(property);
                    complexPropertyMapping.AddTypeMapping(complexTypeMapping);

                    structuralTypeMapping.AddProperty(complexPropertyMapping);
                }

                structuralTypeMapping
                    = complexTypeMapping
                      ?? complexPropertyMapping.TypeMappings.Single();
            }

            // The last property has to be a scalar mapping to the target column.
            // Extract it and create the scalar mapping leaf node, ensuring that we
            // set the target column.

            property = columnMappingBuilder.PropertyPath[i];

            var scalarPropertyMapping
                = structuralTypeMapping
                  .Properties
                  .OfType <StorageScalarPropertyMapping>()
                  .SingleOrDefault(pm => ReferenceEquals(pm.EdmProperty, property));

            if (scalarPropertyMapping == null)
            {
                scalarPropertyMapping
                    = new StorageScalarPropertyMapping(property, columnMappingBuilder.ColumnProperty);

                structuralTypeMapping.AddProperty(scalarPropertyMapping);

                columnMappingBuilder.SetTarget(scalarPropertyMapping);
            }
            else
            {
                scalarPropertyMapping.ColumnProperty = columnMappingBuilder.ColumnProperty;
            }
        }
        private void WritePropertyMapping(StorageComplexPropertyMapping complexPropertyMapping)
        {
            DebugCheck.NotNull(complexPropertyMapping);

            _xmlWriter.WriteStartElement(StorageMslConstructs.ComplexPropertyElement);
            _xmlWriter.WriteAttributeString(StorageMslConstructs.ComplexPropertyNameAttribute, complexPropertyMapping.EdmProperty.Name);
            _xmlWriter.WriteAttributeString(
                StorageMslConstructs.ComplexPropertyTypeNameAttribute,
                _entityTypeNamespace + "." + complexPropertyMapping.EdmProperty.ComplexType.Name);

            foreach (var propertyMapping in complexPropertyMapping.TypeMappings.Single().Properties)
            {
                WritePropertyMapping(propertyMapping);
            }

            _xmlWriter.WriteEndElement();
        }
        /// <summary>
        ///     Recurses down the complex property to find whether any of the nseted properties has concurrency mode set to "Fixed"
        /// </summary>
        /// <param name="complexMapping"> Complex property mapping. Must not be null. </param>
        /// <returns> <c>true</c> if any of the descendant properties has concurrency mode set to "Fixed". Otherwise <c>false</c> . </returns>
        private static bool HasFixedConcurrencyModeInAnyChildProperty(StorageComplexPropertyMapping complexMapping)
        {
            Debug.Assert(complexMapping != null, "complexMapping != null");

            foreach (var propertyMapping in complexMapping.TypeMappings.SelectMany(m => m.AllProperties))
            {
                var childScalarPropertyMapping = propertyMapping as StorageScalarPropertyMapping;
                var childComplexPropertyMapping = propertyMapping as StorageComplexPropertyMapping;

                Debug.Assert(
                    childScalarPropertyMapping != null ||
                    childComplexPropertyMapping != null, "Unimplemented property mapping for complex property");

                //scalar property and has Fixed CC mode
                if (childScalarPropertyMapping != null
                    && MetadataHelper.GetConcurrencyMode(childScalarPropertyMapping.EdmProperty) == ConcurrencyMode.Fixed)
                {
                    return true;
                }
                    // Complex Prop and sub-properties or itself has fixed CC mode
                else if (childComplexPropertyMapping != null
                         &&
                         (MetadataHelper.GetConcurrencyMode(childComplexPropertyMapping.EdmProperty) == ConcurrencyMode.Fixed
                          || HasFixedConcurrencyModeInAnyChildProperty(childComplexPropertyMapping)))
                {
                    return true;
                }
            }

            return false;
        }
        protected override void Visit(StorageComplexPropertyMapping storageComplexPropertyMapping)
        {
            int index;
            if (!AddObjectToSeenListAndHashBuilder(storageComplexPropertyMapping, out index))
            {
                return;
            }

            AddObjectStartDumpToHashBuilder(storageComplexPropertyMapping, index);

            #region Inner data visit

            base.Visit(storageComplexPropertyMapping);

            #endregion

            AddObjectEndDumpToHashBuilder();
        }
 public static string GetIdentity(StorageComplexPropertyMapping mapping)
 {
     return("ComplexProperty(Identity=" + mapping.EdmProperty.Identity + ")");
 }
        public static void GetIdentity_of_StorageComplexPropertyMapping_returns_expected_value()
        {
            var complexType = new ComplexType("CT", "N", DataSpace.CSpace);
            var property = new EdmProperty("A", TypeUsage.Create(complexType));
            StoragePropertyMapping mapping = new StorageComplexPropertyMapping(property);

            Assert.Equal("ComplexProperty(Identity=A)", 
                BaseMetadataMappingVisitor.IdentityHelper.GetIdentity(mapping));
        }
        public static void GetIdentity_of_StorageComplexTypeMapping_returns_expected_value()
        {
            var complexType1 = new ComplexType("CT1", "N", DataSpace.CSpace);
            var complexType2 = new ComplexType("CT2", "N", DataSpace.CSpace);
            var complexType3 = new ComplexType("CT3", "N", DataSpace.CSpace);
            var complexType4 = new ComplexType("CT4", "N", DataSpace.CSpace);
            var property1 = new EdmProperty("A", TypeUsage.Create(complexType1));
            var property2 = new EdmProperty("B", TypeUsage.Create(complexType2));
            var propertyMapping1 = new StorageComplexPropertyMapping(property1);
            var propertyMapping2 = new StorageComplexPropertyMapping(property2);

            var mapping = new StorageComplexTypeMapping(false);
            mapping.AddType(complexType2);
            mapping.AddType(complexType1);
            mapping.AddIsOfType(complexType4);
            mapping.AddIsOfType(complexType3);
            mapping.AddProperty(propertyMapping2);
            mapping.AddProperty(propertyMapping1);

            Assert.Equal("ComplexProperty(Identity=A),ComplexProperty(Identity=B),N.CT1,N.CT2,N.CT3,N.CT4",
                BaseMetadataMappingVisitor.IdentityHelper.GetIdentity(mapping));
        }