Пример #1
0
 private static IEnumerable <ColumnMappingBuilder> GetFlattenedProperties(
     IEnumerable <PropertyMapping> propertyMappings,
     List <EdmProperty> propertyPath)
 {
     foreach (PropertyMapping propertyMapping in propertyMappings)
     {
         propertyPath.Add(propertyMapping.Property);
         ComplexPropertyMapping storageComplexPropertyMapping = propertyMapping as ComplexPropertyMapping;
         if (storageComplexPropertyMapping != null)
         {
             foreach (ColumnMappingBuilder flattenedProperty in MappingFragment.GetFlattenedProperties((IEnumerable <PropertyMapping>)storageComplexPropertyMapping.TypeMappings.Single <ComplexTypeMapping>().PropertyMappings, propertyPath))
             {
                 yield return(flattenedProperty);
             }
         }
         else
         {
             ScalarPropertyMapping storageScalarPropertyMapping = propertyMapping as ScalarPropertyMapping;
             if (storageScalarPropertyMapping != null)
             {
                 yield return(new ColumnMappingBuilder(storageScalarPropertyMapping.Column, (IList <EdmProperty>)propertyPath.ToList <EdmProperty>()));
             }
         }
         propertyPath.Remove(propertyMapping.Property);
     }
 }
Пример #2
0
 protected virtual void Visit(ComplexPropertyMapping complexPropertyMapping)
 {
     this.Visit(complexPropertyMapping.Property);
     foreach (ComplexTypeMapping complexTypeMapping in this.GetSequence <ComplexTypeMapping>((IEnumerable <ComplexTypeMapping>)complexPropertyMapping.TypeMappings, (Func <ComplexTypeMapping, string>)(it => BaseMetadataMappingVisitor.IdentityHelper.GetIdentity(it))))
     {
         this.Visit(complexTypeMapping);
     }
 }
Пример #3
0
 protected virtual void Visit(ComplexPropertyMapping complexPropertyMapping)
 {
     Visit(complexPropertyMapping.Property);
     foreach (var mapping in GetSequence(complexPropertyMapping.TypeMappings, it => IdentityHelper.GetIdentity(it)))
     {
         Visit(mapping);
     }
 }
Пример #4
0
        public void Can_create_mapping_and_get_property()
        {
            var complexType = ComplexType.Create("CT", "NS", DataSpace.CSpace, new EdmMember[0], null);
            var property    = EdmProperty.CreateComplex("P", complexType);
            var mapping     = new ComplexPropertyMapping(property);

            Assert.Same(property, mapping.Property);
        }
        public void Can_create_mapping_and_get_property()
        {
            var complexType = ComplexType.Create("CT", "NS", DataSpace.CSpace, new EdmMember[0], null);
            var property = EdmProperty.CreateComplex("P", complexType);
            var mapping = new ComplexPropertyMapping(property);

            Assert.Same(property, mapping.Property);
        }
        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));
            PropertyMapping mapping     = new ComplexPropertyMapping(property);

            Assert.Equal("ComplexProperty(Identity=A)",
                         BaseMetadataMappingVisitor.IdentityHelper.GetIdentity(mapping));
        }
        protected override void Visit(ComplexPropertyMapping complexPropertyMapping)
        {
            int instanceIndex;

            if (!this.AddObjectToSeenListAndHashBuilder((object)complexPropertyMapping, out instanceIndex))
            {
                return;
            }
            this.AddObjectStartDumpToHashBuilder((object)complexPropertyMapping, instanceIndex);
            base.Visit(complexPropertyMapping);
            this.AddObjectEndDumpToHashBuilder();
        }
Пример #8
0
        public void SetReadOnly_is_called_on_child_mapping_items()
        {
            var complexType = ComplexType.Create("CT", "NS", DataSpace.CSpace, new EdmMember[0], null);
            var property    = EdmProperty.CreateComplex("P", complexType);
            var mapping     = new ComplexPropertyMapping(property);

            var typeMapping = new ComplexTypeMapping(isPartial: false);

            mapping.AddTypeMapping(typeMapping);

            Assert.False(typeMapping.IsReadOnly);
            mapping.SetReadOnly();
            Assert.True(typeMapping.IsReadOnly);
        }
        public void Cannot_add_type_mapping_when_read_only()
        {
            var complexType = ComplexType.Create("CT", "NS", DataSpace.CSpace, new EdmMember[0], null);
            var property = EdmProperty.CreateComplex("P", complexType);
            var mapping = new ComplexPropertyMapping(property);

            mapping.SetReadOnly();

            Assert.True(mapping.IsReadOnly);

            var typeMapping = new ComplexTypeMapping(isPartial: false);

            Assert.Equal(
                Strings.OperationOnReadOnlyItem,
                Assert.Throws<InvalidOperationException>(
                    () => mapping.AddTypeMapping(typeMapping)).Message);
        }
Пример #10
0
        public void Cannot_add_type_mapping_when_read_only()
        {
            var complexType = ComplexType.Create("CT", "NS", DataSpace.CSpace, new EdmMember[0], null);
            var property    = EdmProperty.CreateComplex("P", complexType);
            var mapping     = new ComplexPropertyMapping(property);

            mapping.SetReadOnly();

            Assert.True(mapping.IsReadOnly);

            var typeMapping = new ComplexTypeMapping(isPartial: false);

            Assert.Equal(
                Strings.OperationOnReadOnlyItem,
                Assert.Throws <InvalidOperationException>(
                    () => mapping.AddTypeMapping(typeMapping)).Message);
        }
        public void Can_add_get_remove_type_mappings()
        {
            var complexType = ComplexType.Create("CT", "NS", DataSpace.CSpace, new EdmMember[0], null);
            var property = EdmProperty.CreateComplex("P", complexType);
            var mapping = new ComplexPropertyMapping(property);

            Assert.Equal(0, mapping.TypeMappings.Count);

            var typeMapping = new ComplexTypeMapping(isPartial: false);
            mapping.AddTypeMapping(typeMapping);

            Assert.Equal(1, mapping.TypeMappings.Count);
            Assert.Same(typeMapping, mapping.TypeMappings[0]);

            mapping.RemoveTypeMapping(typeMapping);

            Assert.Equal(0, mapping.TypeMappings.Count);
        }
        protected override void Visit(ComplexPropertyMapping complexPropertyMapping)
        {
            int index;

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

            AddObjectStartDumpToHashBuilder(complexPropertyMapping, index);

            #region Inner data visit

            base.Visit(complexPropertyMapping);

            #endregion

            AddObjectEndDumpToHashBuilder();
        }
Пример #13
0
        public void Can_add_get_remove_type_mappings()
        {
            var complexType = ComplexType.Create("CT", "NS", DataSpace.CSpace, new EdmMember[0], null);
            var property    = EdmProperty.CreateComplex("P", complexType);
            var mapping     = new ComplexPropertyMapping(property);

            Assert.Equal(0, mapping.TypeMappings.Count);

            var typeMapping = new ComplexTypeMapping(isPartial: false);

            mapping.AddTypeMapping(typeMapping);

            Assert.Equal(1, mapping.TypeMappings.Count);
            Assert.Same(typeMapping, mapping.TypeMappings[0]);

            mapping.RemoveTypeMapping(typeMapping);

            Assert.Equal(0, mapping.TypeMappings.Count);
        }
Пример #14
0
        internal void AddColumnMapping(ColumnMappingBuilder columnMappingBuilder)
        {
            Check.NotNull <ColumnMappingBuilder>(columnMappingBuilder, nameof(columnMappingBuilder));
            if (!columnMappingBuilder.PropertyPath.Any <EdmProperty>() || this._columnMappings.Contains(columnMappingBuilder))
            {
                throw new ArgumentException(Strings.InvalidColumnBuilderArgument((object)"columnBuilderMapping"));
            }
            this._columnMappings.Add(columnMappingBuilder);
            StructuralTypeMapping structuralTypeMapping = (StructuralTypeMapping)this;
            int         index;
            EdmProperty property;

            for (index = 0; index < columnMappingBuilder.PropertyPath.Count - 1; ++index)
            {
                property = columnMappingBuilder.PropertyPath[index];
                ComplexPropertyMapping complexPropertyMapping = structuralTypeMapping.PropertyMappings.OfType <ComplexPropertyMapping>().SingleOrDefault <ComplexPropertyMapping>((Func <ComplexPropertyMapping, bool>)(pm => object.ReferenceEquals((object)pm.Property, (object)property)));
                ComplexTypeMapping     typeMapping            = (ComplexTypeMapping)null;
                if (complexPropertyMapping == null)
                {
                    typeMapping = new ComplexTypeMapping(false);
                    typeMapping.AddType(property.ComplexType);
                    complexPropertyMapping = new ComplexPropertyMapping(property);
                    complexPropertyMapping.AddTypeMapping(typeMapping);
                    structuralTypeMapping.AddPropertyMapping((PropertyMapping)complexPropertyMapping);
                }
                structuralTypeMapping = (StructuralTypeMapping)(typeMapping ?? complexPropertyMapping.TypeMappings.Single <ComplexTypeMapping>());
            }
            property = columnMappingBuilder.PropertyPath[index];
            ScalarPropertyMapping scalarPropertyMapping1 = structuralTypeMapping.PropertyMappings.OfType <ScalarPropertyMapping>().SingleOrDefault <ScalarPropertyMapping>((Func <ScalarPropertyMapping, bool>)(pm => object.ReferenceEquals((object)pm.Property, (object)property)));

            if (scalarPropertyMapping1 == null)
            {
                ScalarPropertyMapping scalarPropertyMapping2 = new ScalarPropertyMapping(property, columnMappingBuilder.ColumnProperty);
                structuralTypeMapping.AddPropertyMapping((PropertyMapping)scalarPropertyMapping2);
                columnMappingBuilder.SetTarget(scalarPropertyMapping2);
            }
            else
            {
                scalarPropertyMapping1.Column = columnMappingBuilder.ColumnProperty;
            }
        }
Пример #15
0
        private static void RemoveColumnMapping(
            StructuralTypeMapping structuralTypeMapping,
            IEnumerable <EdmProperty> propertyPath)
        {
            PropertyMapping propertyMapping = structuralTypeMapping.PropertyMappings.Single <PropertyMapping>((Func <PropertyMapping, bool>)(pm => object.ReferenceEquals((object)pm.Property, (object)propertyPath.First <EdmProperty>())));

            if (propertyMapping is ScalarPropertyMapping)
            {
                structuralTypeMapping.RemovePropertyMapping(propertyMapping);
            }
            else
            {
                ComplexPropertyMapping complexPropertyMapping = (ComplexPropertyMapping)propertyMapping;
                ComplexTypeMapping     complexTypeMapping     = complexPropertyMapping.TypeMappings.Single <ComplexTypeMapping>();
                MappingFragment.RemoveColumnMapping((StructuralTypeMapping)complexTypeMapping, propertyPath.Skip <EdmProperty>(1));
                if (complexTypeMapping.PropertyMappings.Any <PropertyMapping>())
                {
                    return;
                }
                structuralTypeMapping.RemovePropertyMapping((PropertyMapping)complexPropertyMapping);
            }
        }
Пример #16
0
            public static string GetIdentity(PropertyMapping mapping)
            {
                ScalarPropertyMapping mapping1 = mapping as ScalarPropertyMapping;

                if (mapping1 != null)
                {
                    return(BaseMetadataMappingVisitor.IdentityHelper.GetIdentity(mapping1));
                }
                ComplexPropertyMapping mapping2 = mapping as ComplexPropertyMapping;

                if (mapping2 != null)
                {
                    return(BaseMetadataMappingVisitor.IdentityHelper.GetIdentity(mapping2));
                }
                EndPropertyMapping mapping3 = mapping as EndPropertyMapping;

                if (mapping3 != null)
                {
                    return(BaseMetadataMappingVisitor.IdentityHelper.GetIdentity(mapping3));
                }
                return(BaseMetadataMappingVisitor.IdentityHelper.GetIdentity((ConditionPropertyMapping)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 ComplexPropertyMapping(property1);
            var propertyMapping2 = new ComplexPropertyMapping(property2);

            var mapping = new ComplexTypeMapping(false);

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

            Assert.Equal("ComplexProperty(Identity=A),ComplexProperty(Identity=B),N.CT1,N.CT2,N.CT3,N.CT4",
                         BaseMetadataMappingVisitor.IdentityHelper.GetIdentity(mapping));
        }
        // <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(ComplexPropertyMapping complexMapping)
        {
            DebugCheck.NotNull(complexMapping);

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

                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.Property) == ConcurrencyMode.Fixed)
                {
                    return true;
                }
                // Complex Prop and sub-properties or itself has fixed CC mode
                else if (childComplexPropertyMapping != null
                         &&
                         (MetadataHelper.GetConcurrencyMode(childComplexPropertyMapping.Property) == ConcurrencyMode.Fixed
                          || HasFixedConcurrencyModeInAnyChildProperty(childComplexPropertyMapping)))
                {
                    return true;
                }
            }

            return false;
        }
Пример #19
0
 public static string GetIdentity(ComplexPropertyMapping mapping)
 {
     return("ComplexProperty(Identity=" + mapping.Property.Identity + ")");
 }
        protected override void Visit(ComplexPropertyMapping complexPropertyMapping)
        {
            int index;
            if (!AddObjectToSeenListAndHashBuilder(complexPropertyMapping, out index))
            {
                return;
            }

            AddObjectStartDumpToHashBuilder(complexPropertyMapping, index);

            #region Inner data visit

            base.Visit(complexPropertyMapping);

            #endregion

            AddObjectEndDumpToHashBuilder();
        }
        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 ComplexPropertyMapping(property1);
            var propertyMapping2 = new ComplexPropertyMapping(property2);

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

            Assert.Equal("ComplexProperty(Identity=A),ComplexProperty(Identity=B),N.CT1,N.CT2,N.CT3,N.CT4",
                BaseMetadataMappingVisitor.IdentityHelper.GetIdentity(mapping));
        }
        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));
            PropertyMapping mapping = new ComplexPropertyMapping(property);

            Assert.Equal("ComplexProperty(Identity=A)", 
                BaseMetadataMappingVisitor.IdentityHelper.GetIdentity(mapping));
        }
Пример #23
0
        private void WritePropertyMapping(ComplexPropertyMapping complexPropertyMapping)
        {
            DebugCheck.NotNull(complexPropertyMapping);

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

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

            _xmlWriter.WriteEndElement();
        }
Пример #24
0
        internal 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
                        .PropertyMappings
                        .OfType<ComplexPropertyMapping>()
                        .SingleOrDefault(pm => ReferenceEquals(pm.Property, property));

                ComplexTypeMapping complexTypeMapping = null;

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

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

                    structuralTypeMapping.AddPropertyMapping(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
                    .PropertyMappings
                    .OfType<ScalarPropertyMapping>()
                    .SingleOrDefault(pm => ReferenceEquals(pm.Property, property));

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

                structuralTypeMapping.AddPropertyMapping(scalarPropertyMapping);

                columnMappingBuilder.SetTarget(scalarPropertyMapping);
            }
            else
            {
                scalarPropertyMapping.Column = columnMappingBuilder.ColumnProperty;
            }
        }
Пример #25
0
        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
                      .PropertyMappings
                      .OfType <ComplexPropertyMapping>()
                      .SingleOrDefault(pm => ReferenceEquals(pm.Property, property));

                ComplexTypeMapping complexTypeMapping = null;

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

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

                    structuralTypeMapping.AddPropertyMapping(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
                  .PropertyMappings
                  .OfType <ScalarPropertyMapping>()
                  .SingleOrDefault(pm => ReferenceEquals(pm.Property, property));

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

                structuralTypeMapping.AddPropertyMapping(scalarPropertyMapping);

                columnMappingBuilder.SetTarget(scalarPropertyMapping);
            }
            else
            {
                scalarPropertyMapping.Column = columnMappingBuilder.ColumnProperty;
            }
        }
        public void SetReadOnly_is_called_on_child_mapping_items()
        {
            var complexType = ComplexType.Create("CT", "NS", DataSpace.CSpace, new EdmMember[0], null);
            var property = EdmProperty.CreateComplex("P", complexType);
            var mapping = new ComplexPropertyMapping(property);

            var typeMapping = new ComplexTypeMapping(isPartial: false);
            mapping.AddTypeMapping(typeMapping);

            Assert.False(typeMapping.IsReadOnly);
            mapping.SetReadOnly();
            Assert.True(typeMapping.IsReadOnly);
        }