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

            var property = new EdmProperty("P");

            mappingFragment.AddColumnMapping(new ColumnMappingBuilder(new EdmProperty("C"), new[] { property }));

            var columnProperty = new EdmProperty("C'");

            var columnMappingBuilder = new ColumnMappingBuilder(columnProperty, new[] { property });

            mappingFragment.AddColumnMapping(columnMappingBuilder);

            var scalarPropertyMapping = (StorageScalarPropertyMapping)mappingFragment.Properties.Single();

            Assert.Same(columnProperty, scalarPropertyMapping.ColumnProperty);
            Assert.Same(property, scalarPropertyMapping.EdmProperty);
        }
        public void Can_get_flattened_properties_for_nested_mapping()
        {
            var mappingFragment
                = new StorageMappingFragment(
                    new EntitySet(),
                    new StorageEntityTypeMapping(
                        new StorageEntitySetMapping(
                            new EntitySet(),
                            new StorageEntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false);

            Assert.Empty(mappingFragment.ColumnMappings);

            var columnProperty = new EdmProperty("C");
            var property1 = EdmProperty.Complex("P1", new ComplexType("CT"));
            var property2 = new EdmProperty("P2");

            var columnMappingBuilder1 = new ColumnMappingBuilder(columnProperty, new[] { property1, property2 });

            mappingFragment.AddColumnMapping(columnMappingBuilder1);

            var columnMappingBuilder2 = new ColumnMappingBuilder(columnProperty, new[] { property2 });

            mappingFragment.AddColumnMapping(columnMappingBuilder2);

            var columnMappingBuilders = mappingFragment.FlattenedProperties.ToList();

            Assert.Equal(2, columnMappingBuilders.Count());
            Assert.True(columnMappingBuilder1.PropertyPath.SequenceEqual(columnMappingBuilders.First().PropertyPath));
            Assert.True(columnMappingBuilder2.PropertyPath.SequenceEqual(columnMappingBuilders.Last().PropertyPath));
        }
        public void Can_update_complex_column_mapping()
        {
            var mappingFragment
                = new StorageMappingFragment(
                      new EntitySet(),
                      new StorageEntityTypeMapping(
                          new StorageEntitySetMapping(
                              new EntitySet(),
                              new StorageEntityContainerMapping(new EntityContainer()))), false);

            var property1 = EdmProperty.Complex("P1", new ComplexType("CT"));
            var property2 = new EdmProperty("P2");

            var columnMappingBuilder1 = new ColumnMappingBuilder(new EdmProperty("C"), new[] { property1, property2 });

            mappingFragment.AddColumnMapping(columnMappingBuilder1);

            var columnProperty = new EdmProperty("C");

            var columnMappingBuilder2 = new ColumnMappingBuilder(columnProperty, new[] { property1, property2 });

            mappingFragment.AddColumnMapping(columnMappingBuilder2);

            var complexPropertyMapping = (StorageComplexPropertyMapping)mappingFragment.Properties.Single();

            var typeMapping = complexPropertyMapping.TypeMappings.Single();

            var scalarPropertyMapping = (StorageScalarPropertyMapping)typeMapping.Properties.Single();

            Assert.Same(columnProperty, scalarPropertyMapping.ColumnProperty);
            Assert.Same(property2, scalarPropertyMapping.EdmProperty);
        }
        public void Can_get_flattened_properties_for_nested_mapping()
        {
            var mappingFragment
                = new StorageMappingFragment(
                      new EntitySet(),
                      new StorageEntityTypeMapping(
                          new StorageEntitySetMapping(
                              new EntitySet(),
                              new StorageEntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false);

            Assert.Empty(mappingFragment.ColumnMappings);

            var columnProperty = new EdmProperty("C");
            var property1      = EdmProperty.Complex("P1", new ComplexType("CT"));
            var property2      = new EdmProperty("P2");

            var columnMappingBuilder1 = new ColumnMappingBuilder(columnProperty, new[] { property1, property2 });

            mappingFragment.AddColumnMapping(columnMappingBuilder1);

            var columnMappingBuilder2 = new ColumnMappingBuilder(columnProperty, new[] { property2 });

            mappingFragment.AddColumnMapping(columnMappingBuilder2);

            var columnMappingBuilders = mappingFragment.FlattenedProperties.ToList();

            Assert.Equal(2, columnMappingBuilders.Count());
            Assert.True(columnMappingBuilder1.PropertyPath.SequenceEqual(columnMappingBuilders.First().PropertyPath));
            Assert.True(columnMappingBuilder2.PropertyPath.SequenceEqual(columnMappingBuilders.Last().PropertyPath));
        }
        public void Can_remove_scalar_column_mapping()
        {
            var mappingFragment
                = new StorageMappingFragment(
                      new EntitySet(),
                      new StorageEntityTypeMapping(
                          new StorageEntitySetMapping(
                              new EntitySet(),
                              new StorageEntityContainerMapping(new EntityContainer()))), false);

            Assert.Empty(mappingFragment.ColumnMappings);

            var columnProperty = new EdmProperty("C");
            var property       = new EdmProperty("P");

            var columnMappingBuilder = new ColumnMappingBuilder(columnProperty, new[] { property });

            mappingFragment.AddColumnMapping(columnMappingBuilder);

            Assert.Same(columnMappingBuilder, mappingFragment.ColumnMappings.Single());
            Assert.NotEmpty(mappingFragment.Properties);

            mappingFragment.RemoveColumnMapping(columnMappingBuilder);

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

            Assert.Empty(mappingFragment.ColumnMappings);

            var columnProperty = new EdmProperty("C");
            var property1      = EdmProperty.Complex("P1", new ComplexType("CT"));
            var property2      = new EdmProperty("P2");

            var columnMappingBuilder = new ColumnMappingBuilder(columnProperty, new[] { property1, property2 });

            mappingFragment.AddColumnMapping(columnMappingBuilder);

            Assert.Same(columnMappingBuilder, mappingFragment.ColumnMappings.Single());
            Assert.NotEmpty(mappingFragment.Properties);

            mappingFragment.RemoveColumnMapping(columnMappingBuilder);

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

            var columnMappingBuilder =
                new ColumnMappingBuilder(new EdmProperty("S"), new[] { new EdmProperty("S") });

            mappingFragment.AddColumnMapping(columnMappingBuilder);

            Assert.Equal(
                Strings.InvalidColumnBuilderArgument("columnBuilderMapping"),
                Assert.Throws <ArgumentException>(
                    () => mappingFragment.AddColumnMapping(columnMappingBuilder)).Message);
        }
Exemplo n.º 8
0
        public void GetComplexPropertyMappings_should_return_all_complex_property_mappings_for_type()
        {
            var databaseMapping = new DbDatabaseMapping()
                .Initialize(new EdmModel(DataSpace.CSpace), new EdmModel(DataSpace.SSpace));
            var entitySet = new EntitySet
                                {
                                    Name = "ES"
                                };
            var entitySetMapping = databaseMapping.AddEntitySetMapping(entitySet);
            var entityTypeMapping = new StorageEntityTypeMapping(null);
            entitySetMapping.AddTypeMapping(entityTypeMapping);
            var entityTypeMappingFragment = new StorageMappingFragment(entitySet, entityTypeMapping, false);
            entityTypeMapping.AddFragment(entityTypeMappingFragment);
            var complexType = new ComplexType("C");
            var propertyMapping1
                = new ColumnMappingBuilder(
                    new EdmProperty("C"),
                    new[]
                        {
                            EdmProperty.Complex("P1", complexType),
                            EdmProperty.Primitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String))
                        });
            var type = typeof(object);

            complexType.Annotations.SetClrType(type);

            entityTypeMappingFragment.AddColumnMapping(propertyMapping1);

            var propertyMapping2
                = new ColumnMappingBuilder(
                    new EdmProperty("C"),
                    new List<EdmProperty>
                        {
                            EdmProperty.Complex("P3", complexType),
                            EdmProperty.Primitive(
                                "P2", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)),
                        });
            entityTypeMappingFragment.AddColumnMapping(propertyMapping2);

            Assert.Equal(2, databaseMapping.GetComplexPropertyMappings(typeof(object)).Count());
        }
        public void Cannot_add_invalid_column_mapping_builder()
        {
            var mappingFragment
                = new StorageMappingFragment(
                      new EntitySet(),
                      new StorageEntityTypeMapping(
                          new StorageEntitySetMapping(
                              new EntitySet(),
                              new StorageEntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false);

            Assert.Equal(
                "columnMappingBuilder",
                Assert.Throws <ArgumentNullException>(
                    () => mappingFragment.AddColumnMapping(null)).ParamName);

            Assert.Equal(
                Strings.InvalidColumnBuilderArgument("columnBuilderMapping"),
                Assert.Throws <ArgumentException>(
                    () => mappingFragment.AddColumnMapping(
                        new ColumnMappingBuilder(new EdmProperty("S"), new List <EdmProperty>()))).Message);
        }
        public void GetPropertyMapping_should_return_mapping_with_path()
        {
            var entityTypeMapping = new StorageEntityTypeMapping(null);
            var propertyFoo = EdmProperty.Complex("Foo", new ComplexType());
            var propertyBar = EdmProperty.Primitive("Bar", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            var entityPropertyMapping
                = new ColumnMappingBuilder(
                    EdmProperty.Primitive("C", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)),
                    new[]
                        {
                            propertyFoo,
                            propertyBar,
                        });

            var entityTypeMappingFragment
                = new StorageMappingFragment(new EntitySet(), entityTypeMapping, false);

            entityTypeMappingFragment.AddColumnMapping(entityPropertyMapping);
            entityTypeMapping.AddFragment(entityTypeMappingFragment);

            Assert.Same(entityPropertyMapping, entityTypeMapping.GetPropertyMapping(propertyFoo, propertyBar));
        }
        public void Can_update_complex_column_mapping()
        {
            var mappingFragment
                = new StorageMappingFragment(
                    new EntitySet(),
                    new StorageEntityTypeMapping(
                        new StorageEntitySetMapping(
                            new EntitySet(),
                            new StorageEntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false);

            var property1 = EdmProperty.Complex("P1", new ComplexType("CT"));
            var property2 = new EdmProperty("P2");

            var columnMappingBuilder1 = new ColumnMappingBuilder(new EdmProperty("C"), new[] { property1, property2 });

            mappingFragment.AddColumnMapping(columnMappingBuilder1);

            var columnProperty = new EdmProperty("C");

            var columnMappingBuilder2 = new ColumnMappingBuilder(columnProperty, new[] { property1, property2 });

            mappingFragment.AddColumnMapping(columnMappingBuilder2);

            var complexPropertyMapping = (StorageComplexPropertyMapping)mappingFragment.Properties.Single();

            var typeMapping = complexPropertyMapping.TypeMappings.Single();

            var scalarPropertyMapping = (StorageScalarPropertyMapping)typeMapping.Properties.Single();

            Assert.Same(columnProperty, scalarPropertyMapping.ColumnProperty);
            Assert.Same(property2, scalarPropertyMapping.EdmProperty);
        }
        public void Can_remove_complex_column_mapping()
        {
            var mappingFragment
                = new StorageMappingFragment(
                    new EntitySet(),
                    new StorageEntityTypeMapping(
                        new StorageEntitySetMapping(
                            new EntitySet(),
                            new StorageEntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false);

            Assert.Empty(mappingFragment.ColumnMappings);

            var columnProperty = new EdmProperty("C");
            var property1 = EdmProperty.Complex("P1", new ComplexType("CT"));
            var property2 = new EdmProperty("P2");

            var columnMappingBuilder = new ColumnMappingBuilder(columnProperty, new[] { property1, property2 });

            mappingFragment.AddColumnMapping(columnMappingBuilder);

            Assert.Same(columnMappingBuilder, mappingFragment.ColumnMappings.Single());
            Assert.NotEmpty(mappingFragment.Properties);

            mappingFragment.RemoveColumnMapping(columnMappingBuilder);

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

            var columnMappingBuilder =
                new ColumnMappingBuilder(new EdmProperty("S"), new[] { new EdmProperty("S") });

            mappingFragment.AddColumnMapping(columnMappingBuilder);

            Assert.Equal(
                Strings.InvalidColumnBuilderArgument("columnBuilderMapping"),
                Assert.Throws<ArgumentException>(
                () => mappingFragment.AddColumnMapping(columnMappingBuilder)).Message);            
        }
        public void Cannot_add_invalid_column_mapping_builder()
        {
            var mappingFragment
                = new StorageMappingFragment(
                    new EntitySet(),
                    new StorageEntityTypeMapping(
                        new StorageEntitySetMapping(
                            new EntitySet(),
                            new StorageEntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false);

            Assert.Equal(
                "columnMappingBuilder",
                Assert.Throws<ArgumentNullException>(
                    () => mappingFragment.AddColumnMapping(null)).ParamName);

            Assert.Equal(
                Strings.InvalidColumnBuilderArgument("columnBuilderMapping"),
                Assert.Throws<ArgumentException>(
                () => mappingFragment.AddColumnMapping(
                    new ColumnMappingBuilder(new EdmProperty("S"), new List<EdmProperty>()))).Message);


        }
        /// <summary>
        ///     Makes sure only the required property mappings are present
        /// </summary>
        private static void ConfigureTypeMappings(
            TableMapping tableMapping,
            Dictionary<EntityType, StorageEntityTypeMapping> rootMappings,
            EntityType entityType,
            StorageMappingFragment propertiesTypeMappingFragment,
            StorageMappingFragment conditionTypeMappingFragment)
        {
            var existingPropertyMappings =
                new List<ColumnMappingBuilder>(
                    propertiesTypeMappingFragment.ColumnMappings.Where(pm => !pm.ColumnProperty.IsPrimaryKeyColumn));
            var existingConditions = new List<StorageConditionPropertyMapping>(propertiesTypeMappingFragment.ColumnConditions);

            foreach (var columnMapping in from cm in tableMapping.ColumnMappings
                                          from pm in cm.PropertyMappings
                                          where pm.EntityType == entityType
                                          select new
                                              {
                                                  cm.Column,
                                                  Property = pm
                                              })
            {
                if (columnMapping.Property.PropertyPath != null
                    &&
                    !IsRootTypeMapping(
                        rootMappings, columnMapping.Property.EntityType, columnMapping.Property.PropertyPath))
                {
                    var existingPropertyMapping =
                        propertiesTypeMappingFragment.ColumnMappings.SingleOrDefault(
                            x => x.PropertyPath == columnMapping.Property.PropertyPath);
                    if (existingPropertyMapping != null)
                    {
                        existingPropertyMappings.Remove(existingPropertyMapping);
                    }
                    else
                    {
                        existingPropertyMapping
                            = new ColumnMappingBuilder(columnMapping.Column, columnMapping.Property.PropertyPath);

                        propertiesTypeMappingFragment.AddColumnMapping(existingPropertyMapping);
                    }
                }

                if (columnMapping.Property.Conditions != null)
                {
                    foreach (var condition in columnMapping.Property.Conditions)
                    {
                        if (conditionTypeMappingFragment.ColumnConditions.Contains(condition))
                        {
                            existingConditions.Remove(condition);
                        }
                        else if (!entityType.Abstract)
                        {
                            conditionTypeMappingFragment.AddConditionProperty(condition);
                        }
                    }
                }
            }

            // Any leftover mappings are removed
            foreach (var leftoverPropertyMapping in existingPropertyMappings)
            {
                propertiesTypeMappingFragment.RemoveColumnMapping(leftoverPropertyMapping);
            }

            foreach (var leftoverCondition in existingConditions)
            {
                conditionTypeMappingFragment.RemoveConditionProperty(leftoverCondition);
            }

            if (entityType.Abstract)
            {
                propertiesTypeMappingFragment.ClearConditions();
            }
        }
        public void Can_add_scalar_column_mapping()
        {
            var mappingFragment
                = new StorageMappingFragment(
                    new EntitySet(),
                    new StorageEntityTypeMapping(
                        new StorageEntitySetMapping(
                            new EntitySet(),
                            new StorageEntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false);

            Assert.Empty(mappingFragment.ColumnMappings);

            var columnProperty = new EdmProperty("C");
            var property = new EdmProperty("P");

            var columnMappingBuilder = new ColumnMappingBuilder(columnProperty, new[] { property });

            mappingFragment.AddColumnMapping(columnMappingBuilder);

            Assert.Same(columnMappingBuilder, mappingFragment.ColumnMappings.Single());

            var scalarPropertyMapping = (StorageScalarPropertyMapping)mappingFragment.Properties.Single();

            Assert.Same(columnProperty, scalarPropertyMapping.ColumnProperty);
            Assert.Same(property, scalarPropertyMapping.EdmProperty);
        }
        public static void MovePropertyMapping(
            EdmModel database,
            StorageMappingFragment fromFragment,
            StorageMappingFragment toFragment,
            ColumnMappingBuilder propertyMappingBuilder,
            bool requiresUpdate,
            bool useExisting)
        {
            // move the column from the formTable to the table in fragment
            if (requiresUpdate && fromFragment.Table != toFragment.Table)
            {
                UpdatePropertyMapping(database, propertyMappingBuilder, fromFragment.Table, toFragment.Table, useExisting);
            }

            // move the propertyMapping
            fromFragment.RemoveColumnMapping(propertyMappingBuilder);
            toFragment.AddColumnMapping(propertyMappingBuilder);
        }
        public static void CopyPropertyMappingToFragment(
            ColumnMappingBuilder propertyMappingBuilder, StorageMappingFragment fragment, bool useExisting)
        {
            // Ensure column is in the fragment's table
            var column = TablePrimitiveOperations.IncludeColumn(fragment.Table, propertyMappingBuilder.ColumnProperty, useExisting);

            // Add the property mapping
            fragment.AddColumnMapping(
                new ColumnMappingBuilder(column, propertyMappingBuilder.PropertyPath));
        }
        public void Generate_should_exclude_sgp_properties_from_corresponding_function_mappings()
        {
            var functionMappingGenerator
                = new ModificationFunctionMappingGenerator(ProviderRegistry.Sql2008_ProviderManifest);

            var databaseMapping
                = new DbDatabaseMapping()
                    .Initialize(new EdmModel(DataSpace.CSpace), new EdmModel(DataSpace.SSpace));

            var entityType = new EntityType("E", "N", DataSpace.CSpace);

            var intProperty = EdmProperty.Primitive("Id", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32));
            intProperty.SetStoreGeneratedPattern(StoreGeneratedPattern.Identity);
            entityType.AddKeyMember(intProperty);

            var stringProperty = EdmProperty.Primitive("Name", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));
            stringProperty.SetStoreGeneratedPattern(StoreGeneratedPattern.Computed);
            entityType.AddMember(stringProperty);

            var entitySetMapping
                = databaseMapping.AddEntitySetMapping(
                    databaseMapping.Model.AddEntitySet("ES", entityType));

            var storageEntityTypeMapping
                = new StorageEntityTypeMapping(
                    new StorageEntitySetMapping(new EntitySet(), databaseMapping.EntityContainerMappings.Single()));

            storageEntityTypeMapping.AddType(entityType);

            var storageMappingFragment = new StorageMappingFragment(new EntitySet(), storageEntityTypeMapping, false);

            storageMappingFragment.AddColumnMapping(
                new ColumnMappingBuilder(new EdmProperty("C0"), new[] { intProperty }));

            storageMappingFragment.AddColumnMapping(
                new ColumnMappingBuilder(new EdmProperty("C1"), new[] { stringProperty }));

            storageEntityTypeMapping.AddFragment(storageMappingFragment);

            entitySetMapping.AddTypeMapping(storageEntityTypeMapping);

            functionMappingGenerator.Generate(entityType, databaseMapping);

            var modificationFunctionMapping
                = entitySetMapping.ModificationFunctionMappings.Single();

            Assert.NotNull(modificationFunctionMapping);

            var functionMapping = modificationFunctionMapping.InsertFunctionMapping;

            Assert.NotNull(functionMapping);
            Assert.Equal(0, functionMapping.ParameterBindings.Count);
            Assert.Equal(2, functionMapping.ResultBindings.Count);

            var function = functionMapping.Function;

            Assert.NotNull(function);
            Assert.Equal("E_Insert", function.Name);
            Assert.Equal(0, function.Parameters.Count);

            functionMapping = modificationFunctionMapping.UpdateFunctionMapping;

            Assert.NotNull(functionMapping);
            Assert.Equal(1, functionMapping.ParameterBindings.Count);
            Assert.Equal(1, functionMapping.ResultBindings.Count);

            function = functionMapping.Function;

            Assert.NotNull(function);
            Assert.Equal("E_Update", function.Name);
            Assert.Equal(1, function.Parameters.Count);

            functionMapping = modificationFunctionMapping.DeleteFunctionMapping;

            Assert.NotNull(functionMapping);
            Assert.Equal(1, functionMapping.ParameterBindings.Count);
            Assert.Null(functionMapping.ResultBindings);

            function = modificationFunctionMapping.DeleteFunctionMapping.Function;

            Assert.NotNull(function);
            Assert.Equal("E_Delete", function.Name);
            Assert.Equal(1, function.Parameters.Count);
        }
        public void Generate(
            EntityType entityType,
            IEnumerable<EdmProperty> properties,
            StorageEntitySetMapping entitySetMapping,
            StorageMappingFragment entityTypeMappingFragment,
            IList<EdmProperty> propertyPath,
            bool createNewColumn)
        {
            DebugCheck.NotNull(entityType);
            DebugCheck.NotNull(properties);
            DebugCheck.NotNull(entityTypeMappingFragment);
            DebugCheck.NotNull(propertyPath);

            var rootDeclaredProperties = entityType.GetRootType().DeclaredProperties;

            foreach (var property in properties)
            {
                if (property.IsComplexType
                    && propertyPath.Any(
                        p => p.IsComplexType
                             && (p.ComplexType == property.ComplexType)))
                {
                    throw Error.CircularComplexTypeHierarchy();
                }

                propertyPath.Add(property);

                if (property.IsComplexType)
                {
                    Generate(
                        entityType,
                        property.ComplexType.Properties,
                        entitySetMapping,
                        entityTypeMappingFragment,
                        propertyPath,
                        createNewColumn);
                }
                else
                {
                    var tableColumn
                        = entitySetMapping.EntityTypeMappings
                                          .SelectMany(etm => etm.MappingFragments)
                                          .SelectMany(etmf => etmf.ColumnMappings)
                                          .Where(pm => pm.PropertyPath.SequenceEqual(propertyPath))
                                          .Select(pm => pm.ColumnProperty)
                                          .FirstOrDefault();

                    if (tableColumn == null || createNewColumn)
                    {
                        var columnName
                            = string.Join("_", propertyPath.Select(p => p.Name));

                        tableColumn
                            = MapTableColumn(
                                property,
                                columnName,
                                !rootDeclaredProperties.Contains(propertyPath.First()));

                        entityTypeMappingFragment.Table.AddColumn(tableColumn);

                        if (entityType.KeyProperties().Contains(property))
                        {
                            entityTypeMappingFragment.Table.AddKeyMember(tableColumn);
                        }
                    }

                    entityTypeMappingFragment.AddColumnMapping(
                        new ColumnMappingBuilder(tableColumn, propertyPath.ToList()));
                }

                propertyPath.Remove(property);
            }
        }