Esempio n. 1
0
        public static void GetIdentity_of_StorageScalarPropertyMapping_returns_expected_value()
        {
            var typeUsage = TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));
            var property1 = new EdmProperty("A", typeUsage);
            var property2 = new EdmProperty("B", typeUsage);
            StoragePropertyMapping mapping = new StorageScalarPropertyMapping(property1, property2);

            Assert.Equal("ScalarProperty(Identity=A,ColumnIdentity=B)",
                         BaseMetadataMappingVisitor.IdentityHelper.GetIdentity(mapping));
        }
        public void Can_get_and_set_column_property()
        {
            var column = new EdmProperty("C");
            var scalarPropertyMapping = new StorageScalarPropertyMapping(new EdmProperty("P"), column);

            Assert.Same(column, scalarPropertyMapping.ColumnProperty);
        
            column = new EdmProperty("C'");

            scalarPropertyMapping.ColumnProperty = column;

            Assert.Same(column, scalarPropertyMapping.ColumnProperty);
        }
        public void Can_get_property_mappings()
        {
            var endPropertyMapping = new StorageEndPropertyMapping(new EdmProperty("P"));

            Assert.Empty(endPropertyMapping.PropertyMappings);

            var scalarPropertyMapping
                = new StorageScalarPropertyMapping(new EdmProperty("P"), new EdmProperty("C"));

            endPropertyMapping.AddProperty(scalarPropertyMapping);

            Assert.Same(scalarPropertyMapping, endPropertyMapping.PropertyMappings.Single());
        }
        public void Can_get_property_mappings()
        {
            var endPropertyMapping = new StorageEndPropertyMapping(new EdmProperty("P"));

            Assert.Empty(endPropertyMapping.PropertyMappings);

            var scalarPropertyMapping 
                = new StorageScalarPropertyMapping(new EdmProperty("P"), new EdmProperty("C"));

            endPropertyMapping.AddProperty(scalarPropertyMapping);

            Assert.Same(scalarPropertyMapping, endPropertyMapping.PropertyMappings.Single());
        }
        public void Can_add_and_remove_properties()
        {
            var complexTypeMapping = new StorageComplexTypeMapping(false);
            var scalarPropertyMapping = new StorageScalarPropertyMapping(new EdmProperty("P"), new EdmProperty("C"));

            Assert.Empty(complexTypeMapping.Properties);

            complexTypeMapping.AddProperty(scalarPropertyMapping);

            Assert.Same(scalarPropertyMapping, complexTypeMapping.Properties.Single());

            complexTypeMapping.RemoveProperty(scalarPropertyMapping);

            Assert.Empty(complexTypeMapping.Properties);
        }
        public void Can_add_and_remove_properties()
        {
            var complexTypeMapping    = new StorageComplexTypeMapping(false);
            var scalarPropertyMapping = new StorageScalarPropertyMapping(new EdmProperty("P"), new EdmProperty("C"));

            Assert.Empty(complexTypeMapping.Properties);

            complexTypeMapping.AddProperty(scalarPropertyMapping);

            Assert.Same(scalarPropertyMapping, complexTypeMapping.Properties.Single());

            complexTypeMapping.RemoveProperty(scalarPropertyMapping);

            Assert.Empty(complexTypeMapping.Properties);
        }
        public void Setting_column_should_update_property_mapping()
        {
            var columnProperty1 = new EdmProperty("C1");
            var property = new EdmProperty("P");
            var columnMappingBuilder = new ColumnMappingBuilder(columnProperty1, new[] { property });
            var scalarPropertyMapping = new StorageScalarPropertyMapping(property, columnProperty1);

            columnMappingBuilder.SetTarget(scalarPropertyMapping);

            var columnProperty2 = new EdmProperty("C2");

            columnMappingBuilder.ColumnProperty = columnProperty2;

            Assert.Same(columnProperty2, columnMappingBuilder.ColumnProperty);
            Assert.Same(columnProperty2, scalarPropertyMapping.ColumnProperty);
        }
        public void Setting_column_should_update_property_mapping()
        {
            var columnProperty1       = new EdmProperty("C1");
            var property              = new EdmProperty("P");
            var columnMappingBuilder  = new ColumnMappingBuilder(columnProperty1, new[] { property });
            var scalarPropertyMapping = new StorageScalarPropertyMapping(property, columnProperty1);

            columnMappingBuilder.SetTarget(scalarPropertyMapping);

            var columnProperty2 = new EdmProperty("C2");

            columnMappingBuilder.ColumnProperty = columnProperty2;

            Assert.Same(columnProperty2, columnMappingBuilder.ColumnProperty);
            Assert.Same(columnProperty2, scalarPropertyMapping.ColumnProperty);
        }
Esempio n. 9
0
        protected override void Visit(StorageScalarPropertyMapping storageScalarPropertyMapping)
        {
            int index;

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

            AddObjectStartDumpToHashBuilder(storageScalarPropertyMapping, index);

            #region Inner data visit

            base.Visit(storageScalarPropertyMapping);

            #endregion

            AddObjectEndDumpToHashBuilder();
        }
        public void Can_add_and_remove_properties()
        {
            var mappingFragment
                = new StorageMappingFragment(
                      new EntitySet(),
                      new StorageEntityTypeMapping(
                          new StorageEntitySetMapping(
                              new EntitySet(),
                              new StorageEntityContainerMapping(new EntityContainer()))), false);

            Assert.Empty(mappingFragment.Properties);

            var scalarPropertyMapping = new StorageScalarPropertyMapping(new EdmProperty("P"), new EdmProperty("C"));

            mappingFragment.AddProperty(scalarPropertyMapping);

            Assert.Same(scalarPropertyMapping, mappingFragment.Properties.Single());

            mappingFragment.RemoveProperty(scalarPropertyMapping);

            Assert.Empty(mappingFragment.Properties);
        }
        public void Can_add_and_remove_properties()
        {
            var mappingFragment
                = new StorageMappingFragment(
                    new EntitySet(),
                    new StorageEntityTypeMapping(
                        new StorageEntitySetMapping(
                            new EntitySet(),
                            new StorageEntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false);

            Assert.Empty(mappingFragment.Properties);

            var scalarPropertyMapping = new StorageScalarPropertyMapping(new EdmProperty("P"), new EdmProperty("C"));

            mappingFragment.AddProperty(scalarPropertyMapping);

            Assert.Same(scalarPropertyMapping, mappingFragment.Properties.Single());

            mappingFragment.RemoveProperty(scalarPropertyMapping);

            Assert.Empty(mappingFragment.Properties);
        }
Esempio n. 12
0
 public void SetTarget(StorageScalarPropertyMapping scalarPropertyMapping)
 {
     _scalarPropertyMapping = scalarPropertyMapping;
 }
 internal void SetTarget(StorageScalarPropertyMapping scalarPropertyMapping)
 {
     _scalarPropertyMapping = scalarPropertyMapping;
 }
 protected virtual void Visit(StorageScalarPropertyMapping storageScalarPropertyMapping)
 {
     Visit(storageScalarPropertyMapping.ColumnProperty);
     Visit(storageScalarPropertyMapping.EdmProperty);
 }
 internal void SetTarget(StorageScalarPropertyMapping scalarPropertyMapping)
 {
     _scalarPropertyMapping = scalarPropertyMapping;
 }
        public static void GetIdentity_of_StorageScalarPropertyMapping_returns_expected_value()
        {
            var typeUsage = TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));
            var property1 = new EdmProperty("A", typeUsage);
            var property2 = new EdmProperty("B", typeUsage);
            StoragePropertyMapping mapping = new StorageScalarPropertyMapping(property1, property2);

            Assert.Equal("ScalarProperty(Identity=A,ColumnIdentity=B)", 
                BaseMetadataMappingVisitor.IdentityHelper.GetIdentity(mapping));
        }
 protected virtual void Visit(StorageScalarPropertyMapping storageScalarPropertyMapping)
 {
     Visit(storageScalarPropertyMapping.ColumnProperty);
     Visit(storageScalarPropertyMapping.EdmProperty);
 }
        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;
            }
        }
Esempio n. 19
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;
            }
        }
 public static string GetIdentity(StorageScalarPropertyMapping mapping)
 {
     return("ScalarProperty(Identity=" + mapping.EdmProperty.Identity
            + ",ColumnIdentity=" + mapping.ColumnProperty.Identity + ")");
 }
        private void WritePropertyMapping(StorageScalarPropertyMapping scalarPropertyMapping)
        {
            DebugCheck.NotNull(scalarPropertyMapping);

            WriteScalarPropertyElement(scalarPropertyMapping.EdmProperty, scalarPropertyMapping.ColumnProperty);
        }
        protected override void Visit(StorageScalarPropertyMapping storageScalarPropertyMapping)
        {
            int index;
            if (!AddObjectToSeenListAndHashBuilder(storageScalarPropertyMapping, out index))
            {
                return;
            }

            AddObjectStartDumpToHashBuilder(storageScalarPropertyMapping, index);

            #region Inner data visit

            base.Visit(storageScalarPropertyMapping);

            #endregion

            AddObjectEndDumpToHashBuilder();
        }