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_remove_complex_column_mapping() { var mappingFragment = new MappingFragment( new EntitySet(), new EntityTypeMapping( new EntitySetMapping( new EntitySet(), new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false); Assert.Empty(mappingFragment.ColumnMappings); var columnProperty = new EdmProperty("C", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace })); var property1 = EdmProperty.CreateComplex("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.PropertyMappings); mappingFragment.RemoveColumnMapping(columnMappingBuilder); Assert.Empty(mappingFragment.ColumnMappings); Assert.Empty(mappingFragment.PropertyMappings); }
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 MappingFragment( new EntitySet(), new EntityTypeMapping( new EntitySetMapping( new EntitySet(), new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false); Assert.Empty(mappingFragment.ColumnMappings); var columnProperty = new EdmProperty("C", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace })); var property1 = EdmProperty.CreateComplex("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_add_scalar_column_mapping() { var mappingFragment = new MappingFragment( new EntitySet(), new EntityTypeMapping( new EntitySetMapping( new EntitySet(), new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false); Assert.Empty(mappingFragment.ColumnMappings); var columnProperty = new EdmProperty("C", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace })); var property = new EdmProperty("P"); var columnMappingBuilder = new ColumnMappingBuilder(columnProperty, new[] { property }); mappingFragment.AddColumnMapping(columnMappingBuilder); Assert.Same(columnMappingBuilder, mappingFragment.ColumnMappings.Single()); var scalarPropertyMapping = (ScalarPropertyMapping)mappingFragment.PropertyMappings.Single(); Assert.Same(columnProperty, scalarPropertyMapping.Column); Assert.Same(property, scalarPropertyMapping.Property); }
public void Can_initialize_column_mapping_builder() { var columnProperty = new EdmProperty("C"); var property = new EdmProperty("P"); var columnMappingBuilder = new ColumnMappingBuilder(columnProperty, new[] { property }); Assert.Same(columnProperty, columnMappingBuilder.ColumnProperty); Assert.Same(property, columnMappingBuilder.PropertyPath.Single()); }
public void RemoveColumnMapping(ColumnMappingBuilder columnMappingBuilder) { DebugCheck.NotNull(columnMappingBuilder); DebugCheck.NotNull(columnMappingBuilder.ColumnProperty); Debug.Assert(columnMappingBuilder.PropertyPath.Any()); Debug.Assert(_columnMappings.Contains(columnMappingBuilder)); _columnMappings.Remove(columnMappingBuilder); RemoveColumnMapping(this, columnMappingBuilder.PropertyPath); }
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", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace })); var property = new EdmProperty("P"); var columnMappingBuilder = new ColumnMappingBuilder(columnProperty1, new[] { property }); var scalarPropertyMapping = new ScalarPropertyMapping(property, columnProperty1); columnMappingBuilder.SetTarget(scalarPropertyMapping); var columnProperty2 = new EdmProperty("C2", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace })); columnMappingBuilder.ColumnProperty = columnProperty2; Assert.Same(columnProperty2, columnMappingBuilder.ColumnProperty); Assert.Same(columnProperty2, scalarPropertyMapping.Column); }
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 Configure_should_update_IsRowVersion() { var configuration = CreateConfiguration(); configuration.IsRowVersion = true; var property = EdmProperty.CreatePrimitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); configuration.Configure(property); Assert.Equal(8, property.MaxLength); Assert.Equal(false, property.Nullable); Assert.Equal(ConcurrencyMode.Fixed, property.ConcurrencyMode); Assert.Equal(StoreGeneratedPattern.Computed, property.GetStoreGeneratedPattern()); var edmPropertyMapping = new ColumnMappingBuilder(new EdmProperty("C"), new List<EdmProperty>()); configuration.Configure( new[] { Tuple.Create(edmPropertyMapping, new EntityType("T", XmlConstants.TargetNamespace_3, DataSpace.SSpace)) }, ProviderRegistry.Sql2008_ProviderManifest); Assert.Equal("rowversion", edmPropertyMapping.ColumnProperty.TypeName); }
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()); }
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; } }
public void Configure_should_update_IsUnicode() { var configuration = CreateConfiguration(); configuration.IsUnicode = true; var property = EdmProperty.CreatePrimitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); configuration.Configure(property); Assert.Equal(true, property.IsUnicode); var edmPropertyMapping = new ColumnMappingBuilder( new EdmProperty( "C", TypeUsage.Create(ProviderRegistry.Sql2008_ProviderManifest.GetStoreTypes().First(t => t.Name == "nvarchar"))), new List<EdmProperty>()); configuration.Configure( new[] { Tuple.Create(edmPropertyMapping, new EntityType("T", XmlConstants.TargetNamespace_3, DataSpace.SSpace)) }, ProviderRegistry.Sql2008_ProviderManifest); Assert.Equal(true, edmPropertyMapping.ColumnProperty.IsUnicode); }
public void Configure_should_update_model_dateTime_precision() { var configuration = CreateConfiguration(); configuration.Precision = 255; var property = EdmProperty.CreatePrimitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.DateTime)); configuration.Configure(property); Assert.Equal((byte)255, property.Precision); var edmPropertyMapping = new ColumnMappingBuilder( new EdmProperty( "C", TypeUsage.Create(ProviderRegistry.Sql2008_ProviderManifest.GetStoreTypes().First(t => t.Name == "datetime2"))), new List<EdmProperty>()); configuration.Configure( new[] { Tuple.Create(edmPropertyMapping, new EntityType("T", XmlConstants.TargetNamespace_3, DataSpace.SSpace)) }, ProviderRegistry.Sql2008_ProviderManifest); Assert.Equal((byte)255, edmPropertyMapping.ColumnProperty.Precision); }
public void Can_update_complex_column_mapping() { var mappingFragment = new MappingFragment( new EntitySet(), new EntityTypeMapping( new EntitySetMapping( new EntitySet(), new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false); var property1 = EdmProperty.CreateComplex("P1", new ComplexType("CT")); var property2 = new EdmProperty("P2"); var columnMappingBuilder1 = new ColumnMappingBuilder(new EdmProperty("C", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace })), new[] { property1, property2 }); mappingFragment.AddColumnMapping(columnMappingBuilder1); var columnProperty = new EdmProperty("C", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace })); var columnMappingBuilder2 = new ColumnMappingBuilder(columnProperty, new[] { property1, property2 }); mappingFragment.AddColumnMapping(columnMappingBuilder2); var complexPropertyMapping = (ComplexPropertyMapping)mappingFragment.PropertyMappings.Single(); var typeMapping = complexPropertyMapping.TypeMappings.Single(); var scalarPropertyMapping = (ScalarPropertyMapping)typeMapping.PropertyMappings.Single(); Assert.Same(columnProperty, scalarPropertyMapping.Column); Assert.Same(property2, scalarPropertyMapping.Property); }
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_scalar_column_mapping() { var mappingFragment = new StorageMappingFragment( new EntitySet(), new StorageEntityTypeMapping( new StorageEntitySetMapping( new EntitySet(), new StorageEntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), 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 Configure_should_set_SSpace_configuration_annotation() { var configuration = CreateConfiguration(); var edmPropertyMapping = new ColumnMappingBuilder(new EdmProperty("C"), new List<EdmProperty>()); Assert.Null(edmPropertyMapping.ColumnProperty.GetConfiguration()); configuration.Configure( new[] { Tuple.Create( edmPropertyMapping, new EntityType("T", XmlConstants.TargetNamespace_3, DataSpace.SSpace)) }, ProviderRegistry.Sql2008_ProviderManifest); Assert.NotNull(edmPropertyMapping.ColumnProperty.GetConfiguration()); }
// <summary> // Makes sure only the required property mappings are present // </summary> private static void ConfigureTypeMappings( TableMapping tableMapping, Dictionary<EntityType, EntityTypeMapping> rootMappings, EntityType entityType, MappingFragment propertiesTypeMappingFragment, MappingFragment conditionTypeMappingFragment) { var existingPropertyMappings = new List<ColumnMappingBuilder>( propertiesTypeMappingFragment.ColumnMappings.Where(pm => !pm.ColumnProperty.IsPrimaryKeyColumn)); var existingConditions = new List<ConditionPropertyMapping>(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_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()); 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); }
internal void RemoveColumnMapping(ColumnMappingBuilder columnMappingBuilder) { DebugCheck.NotNull(columnMappingBuilder); DebugCheck.NotNull(columnMappingBuilder.ColumnProperty); Debug.Assert(columnMappingBuilder.PropertyPath.Any()); Debug.Assert(_columnMappings.Contains(columnMappingBuilder)); _columnMappings.Remove(columnMappingBuilder); RemoveColumnMapping(this, columnMappingBuilder.PropertyPath); }
private static EntityType FindTableForTemporaryExtraPropertyMapping( DbDatabaseMapping databaseMapping, EntityType entityType, EntityType fromTable, EntityType toTable, ColumnMappingBuilder pm) { var extraTable = fromTable; if (fromTable == toTable) { extraTable = databaseMapping.Database.AddTable(entityType.Name, fromTable); } else if (entityType.BaseType == null) { extraTable = fromTable; } else { // find where the base mappings are and put them in that table extraTable = FindBaseTableForExtraPropertyMapping(databaseMapping, entityType, pm); if (extraTable == null) { extraTable = fromTable; } } return extraTable; }
public void Configure_should_update_column_annotations() { var configuration = CreateConfiguration(); configuration.SetAnnotation("A1", "V1"); configuration.SetAnnotation("A2", "V2"); configuration.SetAnnotation("A3", "V3"); configuration.SetAnnotation("A1", "V4"); configuration.SetAnnotation("A3", null); var edmPropertyMapping = new ColumnMappingBuilder(new EdmProperty("C"), new List<EdmProperty>()); configuration.Configure( new[] { Tuple.Create(edmPropertyMapping, new EntityType("T", XmlConstants.TargetNamespace_3, DataSpace.SSpace)) }, ProviderRegistry.Sql2008_ProviderManifest); Assert.Equal( "V4", edmPropertyMapping.ColumnProperty.Annotations.Single(a => a.Name == XmlConstants.CustomAnnotationPrefix + "A1").Value); Assert.Equal( "V2", edmPropertyMapping.ColumnProperty.Annotations.Single(a => a.Name == XmlConstants.CustomAnnotationPrefix + "A2").Value); Assert.False(edmPropertyMapping.ColumnProperty.Annotations.Any(a => a.Name == XmlConstants.CustomAnnotationPrefix + "A3")); }
private static EntityType FindTableForExtraPropertyMapping( DbDatabaseMapping databaseMapping, EntityType entityType, EntityType fromTable, EntityType toTable, ref EntityType unmappedTable, ColumnMappingBuilder pm) { var extraTable = FindBaseTableForExtraPropertyMapping(databaseMapping, entityType, pm); if (extraTable == null) { if (fromTable != toTable && entityType.BaseType == null) { return fromTable; } if (unmappedTable == null) { unmappedTable = databaseMapping.Database.AddTable(fromTable.Name, fromTable); } extraTable = unmappedTable; } return extraTable; }
public void Cannot_add_duplicate_column_mapping_builder() { var mappingFragment = new MappingFragment( new EntitySet(), new EntityTypeMapping( new EntitySetMapping( new EntitySet(), new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false); var columnMappingBuilder = new ColumnMappingBuilder(new EdmProperty("S", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace })), new[] { new EdmProperty("S") }); mappingFragment.AddColumnMapping(columnMappingBuilder); Assert.Equal( Strings.InvalidColumnBuilderArgument("columnBuilderMapping"), Assert.Throws<ArgumentException>( () => mappingFragment.AddColumnMapping(columnMappingBuilder)).Message); }
private static EntityType FindBaseTableForExtraPropertyMapping( DbDatabaseMapping databaseMapping, EntityType entityType, ColumnMappingBuilder pm) { var baseType = (EntityType)entityType.BaseType; StorageMappingFragment baseFragment = null; while (baseType != null && baseFragment == null) { var baseMapping = databaseMapping.GetEntityTypeMapping(baseType); if (baseMapping != null) { baseFragment = baseMapping.MappingFragments.SingleOrDefault( f => f.ColumnMappings.Any(bpm => bpm.PropertyPath.SequenceEqual(pm.PropertyPath))); if (baseFragment != null) { return baseFragment.Table; } } baseType = (EntityType)baseType.BaseType; } return null; }
private static void UpdatePropertyMapping( DbDatabaseMapping databaseMapping, IEnumerable<EntitySet> entitySets, Dictionary<EdmProperty, IList<ColumnMappingBuilder>> columnMappingIndex, ColumnMappingBuilder propertyMappingBuilder, EntityType fromTable, EntityType toTable, bool useExisting) { propertyMappingBuilder.ColumnProperty = TableOperations.CopyColumnAndAnyConstraints( databaseMapping.Database, fromTable, toTable, propertyMappingBuilder.ColumnProperty, GetPropertyPathMatcher(columnMappingIndex, propertyMappingBuilder), useExisting); propertyMappingBuilder.SyncNullabilityCSSpace(databaseMapping, entitySets, toTable); }
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; } }
public void Configure_should_set_SSpace_configuration_annotation_with_forced_overridability() { var configuration = CreateConfiguration(); configuration.OverridableConfigurationParts = OverridableConfigurationParts.None; var edmPropertyMapping = new ColumnMappingBuilder(new EdmProperty("C"), new List<EdmProperty>()); Assert.Null(edmPropertyMapping.ColumnProperty.GetConfiguration()); configuration.Configure( new[] { Tuple.Create( edmPropertyMapping, new EntityType("T", XmlConstants.TargetNamespace_3, DataSpace.SSpace)) }, ProviderRegistry.Sql2008_ProviderManifest, allowOverride: true); configuration = (Properties.Primitive.PrimitivePropertyConfiguration)edmPropertyMapping.ColumnProperty.GetConfiguration(); Assert.NotNull(configuration); Assert.Equal(OverridableConfigurationParts.OverridableInSSpace, configuration.OverridableConfigurationParts); }
public void Configure_should_merge_SSpace_configurations_if_existing_is_not_overridable() { var configurationA = CreateConfiguration(); configurationA.ColumnName = "foo"; configurationA.OverridableConfigurationParts = OverridableConfigurationParts.OverridableInCSpace; var configurationB = CreateConfiguration(); configurationB.ColumnType = "nvarchar"; var edmPropertyMapping = new ColumnMappingBuilder(new EdmProperty("C"), new List<EdmProperty>()); configurationA.Configure( new[] { Tuple.Create(edmPropertyMapping, new EntityType("T", XmlConstants.TargetNamespace_3, DataSpace.SSpace)) }, ProviderRegistry.Sql2008_ProviderManifest); Assert.Equal( "foo", ((Properties.Primitive.PrimitivePropertyConfiguration)edmPropertyMapping.ColumnProperty.GetConfiguration()).ColumnName); configurationB.Configure( new[] { Tuple.Create(edmPropertyMapping, new EntityType("T", XmlConstants.TargetNamespace_3, DataSpace.SSpace)) }, ProviderRegistry.Sql2008_ProviderManifest); Assert.Equal( "foo", ((Properties.Primitive.PrimitivePropertyConfiguration)edmPropertyMapping.ColumnProperty.GetConfiguration()).ColumnName); Assert.Equal( OverridableConfigurationParts.OverridableInCSpace, ((Properties.Primitive.PrimitivePropertyConfiguration)edmPropertyMapping.ColumnProperty.GetConfiguration()).OverridableConfigurationParts); Assert.Equal( "nvarchar", ((Properties.Primitive.PrimitivePropertyConfiguration)edmPropertyMapping.ColumnProperty.GetConfiguration()).ColumnType); }
public void Configure_should_update_mapped_column_type() { var configuration = CreateConfiguration(); configuration.ColumnType = "NVarchaR(max)"; var edmPropertyMapping = new ColumnMappingBuilder(new EdmProperty("C"), new List<EdmProperty>()); configuration.Configure( new[] { Tuple.Create(edmPropertyMapping, new EntityType("T", XmlConstants.TargetNamespace_3, DataSpace.SSpace)) }, ProviderRegistry.Sql2008_ProviderManifest); Assert.Equal("nvarchar(max)", edmPropertyMapping.ColumnProperty.TypeName); }
public static void MovePropertyMapping( DbDatabaseMapping databaseMapping, IEnumerable<EntitySet> entitySets, MappingFragment fromFragment, MappingFragment 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(databaseMapping, entitySets, GetColumnMappingIndex(databaseMapping), propertyMappingBuilder, fromFragment.Table, toFragment.Table, useExisting); } // move the propertyMapping fromFragment.RemoveColumnMapping(propertyMappingBuilder); toFragment.AddColumnMapping(propertyMappingBuilder); }
private static Func<EdmProperty, bool> GetPropertyPathMatcher(Dictionary<EdmProperty, IList<ColumnMappingBuilder>> columnMappingIndex, ColumnMappingBuilder propertyMappingBuilder) { return c => { if (!columnMappingIndex.ContainsKey(c)) return false; var columnMappingList = columnMappingIndex[c]; // ReSharper disable once LoopCanBeConvertedToQuery // ReSharper disable once ForCanBeConvertedToForeach for (var iter = 0; iter < columnMappingList.Count; ++iter) { var columnMapping = columnMappingList[iter]; if (columnMapping.PropertyPath.PathEqual(propertyMappingBuilder.PropertyPath)) { return true; } } return false; }; }
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 void CopyPropertyMappingToFragment( ColumnMappingBuilder propertyMappingBuilder, MappingFragment fragment, Func<EdmProperty, bool> isCompatible, bool useExisting) { // Ensure column is in the fragment's table var column = TablePrimitiveOperations.IncludeColumn(fragment.Table, propertyMappingBuilder.ColumnProperty, isCompatible, useExisting); // Add the property mapping fragment.AddColumnMapping( new ColumnMappingBuilder(column, propertyMappingBuilder.PropertyPath)); }
internal void RemoveColumnMapping(ColumnMappingBuilder columnMappingBuilder) { this._columnMappings.Remove(columnMappingBuilder); MappingFragment.RemoveColumnMapping((StructuralTypeMapping)this, (IEnumerable <EdmProperty>)columnMappingBuilder.PropertyPath); }