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_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 AddEntityTypeMappingFragment( EntitySet entitySet, EntityType entityType, StorageMappingFragment fragment) { Debug.Assert(fragment.Table == Table); _entityTypes.Add(entitySet, entityType); var defaultDiscriminatorColumn = fragment.GetDefaultDiscriminator(); StorageConditionPropertyMapping defaultDiscriminatorCondition = null; if (defaultDiscriminatorColumn != null) { defaultDiscriminatorCondition = fragment.ColumnConditions.SingleOrDefault(cc => cc.ColumnProperty == defaultDiscriminatorColumn); } foreach (var pm in fragment.ColumnMappings) { var columnMapping = FindOrCreateColumnMapping(pm.ColumnProperty); columnMapping.AddMapping( entityType, pm.PropertyPath, fragment.ColumnConditions.Where(cc => cc.ColumnProperty == pm.ColumnProperty), defaultDiscriminatorColumn == pm.ColumnProperty); } // Add any column conditions that aren't mapped to properties foreach ( var cc in fragment.ColumnConditions.Where(cc => !fragment.ColumnMappings.Any(pm => pm.ColumnProperty == cc.ColumnProperty))) { var columnMapping = FindOrCreateColumnMapping(cc.ColumnProperty); columnMapping.AddMapping(entityType, null, new[] { cc }, defaultDiscriminatorColumn == cc.ColumnProperty); } }
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 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 WriteMappingFragment_should_write_store_entity_set_name() { var fixture = new Fixture(); var entityType = new EntityType("E", "N", DataSpace.CSpace); var entitySet = new EntitySet("ES", "S", null, null, entityType); var entityContainer = new EntityContainer("EC", DataSpace.SSpace); entityContainer.AddEntitySetBase(entitySet); var storageEntitySetMapping = new StorageEntitySetMapping( entitySet, new StorageEntityContainerMapping(entityContainer)); StorageTypeMapping typeMapping = new StorageEntityTypeMapping(storageEntitySetMapping); var mappingFragment = new StorageMappingFragment(entitySet, typeMapping, false); fixture.Writer.WriteMappingFragmentElement(mappingFragment); Assert.Equal( @"<MappingFragment StoreEntitySet=""ES"" />", fixture.ToString()); }
protected virtual void Visit(StorageMappingFragment storageMappingFragment) { foreach (var property in storageMappingFragment.AllProperties) { Visit(property); } Visit((EntitySetBase)storageMappingFragment.TableSet); }
protected virtual void Visit(StorageMappingFragment storageMappingFragment) { foreach (var property in GetSequence(storageMappingFragment.AllProperties, it => IdentityHelper.GetIdentity(it))) { Visit(property); } Visit((EntitySetBase)storageMappingFragment.TableSet); }
public static void GetIdentity_of_StorageMappingFragment_returns_expected_value() { var entityType = new EntityType("ET", "N", DataSpace.CSpace); var entitySet = new EntitySet("ES", "S", "T", null, entityType); var entityTypeMapping = new StorageEntityTypeMapping(null); entityTypeMapping.AddType(entityType); var mappingFragment = new StorageMappingFragment(entitySet, entityTypeMapping, false); Assert.Equal(entitySet.Identity, BaseMetadataMappingVisitor.IdentityHelper.GetIdentity(mappingFragment)); }
internal StorageAssociationSetMapping(AssociationSet extent, EntitySet entitySet) : base(extent, null) { DebugCheck.NotNull(entitySet); var associationTypeMapping = new StorageAssociationTypeMapping(extent.ElementType, this); var mappingFragment = new StorageMappingFragment(entitySet, associationTypeMapping, false); associationTypeMapping.AddFragment(mappingFragment); AddTypeMapping(associationTypeMapping); }
public void Can_get_table() { var table = new EntityType(); var tableSet = new EntitySet("ES", null, null, null, table); var mappingFragment = new StorageMappingFragment( tableSet, new StorageEntityTypeMapping( new StorageEntitySetMapping( new EntitySet(), new StorageEntityContainerMapping(new EntityContainer()))), false); Assert.Same(table, mappingFragment.Table); }
internal void Configure( DbDatabaseMapping databaseMapping, StorageMappingFragment fragment, EntityType entityType) { DebugCheck.NotNull(fragment); var edmPropertyPath = EntityMappingConfiguration.PropertyPathToEdmPropertyPath(PropertyPath, entityType); if (edmPropertyPath.Count() > 1) { throw Error.InvalidNotNullCondition(PropertyPath.ToString(), entityType.Name); } var column = fragment.ColumnMappings .Where(pm => pm.PropertyPath.SequenceEqual(edmPropertyPath.Single())) .Select(pm => pm.ColumnProperty) .SingleOrDefault(); if (column == null || !fragment.Table.Properties.Contains(column)) { throw Error.InvalidNotNullCondition(PropertyPath.ToString(), entityType.Name); } if (ValueConditionConfiguration.AnyBaseTypeToTableWithoutColumnCondition( databaseMapping, entityType, fragment.Table, column)) { column.Nullable = true; } // Make the property required var newConfiguration = new Properties.Primitive.PrimitivePropertyConfiguration { IsNullable = false, OverridableConfigurationParts = OverridableConfigurationParts.OverridableInSSpace }; newConfiguration.Configure(edmPropertyPath.Single().Last()); fragment.AddNullabilityCondition(column, isNull: false); }
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 Can_get_and_set_table_set() { var tableSet = new EntitySet(); var mappingFragment = new StorageMappingFragment( tableSet, new StorageEntityTypeMapping( new StorageEntitySetMapping( new EntitySet(), new StorageEntityContainerMapping(new EntityContainer()))), false); Assert.Same(tableSet, mappingFragment.TableSet); tableSet = new EntitySet(); mappingFragment.TableSet = tableSet; Assert.Same(tableSet, mappingFragment.TableSet); }
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); }
protected override void Visit(StorageMappingFragment storageMappingFragment) { int index; if (!AddObjectToSeenListAndHashBuilder(storageMappingFragment, out index)) { return; } AddObjectStartDumpToHashBuilder(storageMappingFragment, index); #region Inner data visit AddV2ObjectContentToHashBuilder(storageMappingFragment.IsSQueryDistinct, m_MappingVersion); base.Visit(storageMappingFragment); #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("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); }
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_remove_mapping_fragment() { var storageSetMapping = new StorageEntitySetMapping( new EntitySet(), new StorageEntityContainerMapping(new EntityContainer())); var storageTypeMapping = new StorageEntityTypeMapping(storageSetMapping); Assert.Empty(storageTypeMapping.MappingFragments); var mappingFragment = new StorageMappingFragment(new EntitySet(), storageTypeMapping, false); storageTypeMapping.AddFragment(mappingFragment); Assert.Same(mappingFragment, storageTypeMapping.MappingFragments.Single()); storageTypeMapping.RemoveFragment(mappingFragment); Assert.Empty(storageTypeMapping.MappingFragments); }
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_add_and_remove_column_conditions() { var mappingFragment = new StorageMappingFragment( new EntitySet(), new StorageEntityTypeMapping( new StorageEntitySetMapping( new EntitySet(), new StorageEntityContainerMapping(new EntityContainer()))), false); Assert.Empty(mappingFragment.ColumnConditions); var conditionPropertyMapping = new StorageConditionPropertyMapping(null, new EdmProperty("C"), 42, null); mappingFragment.AddConditionProperty(conditionPropertyMapping); Assert.Same(conditionPropertyMapping, mappingFragment.ColumnConditions.Single()); mappingFragment.RemoveConditionProperty(conditionPropertyMapping); Assert.Empty(mappingFragment.ColumnConditions); }
public void Generate(EntityType entityType, DbDatabaseMapping databaseMapping) { DebugCheck.NotNull(entityType); DebugCheck.NotNull(databaseMapping); var entitySet = databaseMapping.Model.GetEntitySet(entityType); var entitySetMapping = databaseMapping.GetEntitySetMapping(entitySet) ?? databaseMapping.AddEntitySetMapping(entitySet); var table = entitySetMapping.EntityTypeMappings.Any() ? entitySetMapping.EntityTypeMappings.First().MappingFragments.First().Table : databaseMapping.Database.AddTable(entityType.GetRootType().Name); var entityTypeMapping = new StorageEntityTypeMapping(null); var entityTypeMappingFragment = new StorageMappingFragment(databaseMapping.Database.GetEntitySet(table), entityTypeMapping, false); entityTypeMapping.AddType(entityType); entityTypeMapping.AddFragment(entityTypeMappingFragment); entityTypeMapping.SetClrType(entityType.GetClrType()); entitySetMapping.AddTypeMapping(entityTypeMapping); new PropertyMappingGenerator(_providerManifest) .Generate( entityType, entityType.Properties, entitySetMapping, entityTypeMappingFragment, new List<EdmProperty>(), false); }
/// <summary> /// Add a fragment mapping as child of this type mapping /// </summary> /// <param name="fragment"> </param> internal void AddFragment(StorageMappingFragment fragment) { m_fragments.Add(fragment); }
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); }
internal void RemoveFragment(StorageMappingFragment fragment) { DebugCheck.NotNull(fragment); m_fragments.Remove(fragment); }
/// <summary> /// Add a fragment mapping as child of this type mapping /// </summary> /// <param name="fragment"> </param> public void AddFragment(StorageMappingFragment fragment) { Check.NotNull(fragment, "fragment"); m_fragments.Add(fragment); }
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 Can_get_and_set_table_set() { var tableSet = new EntitySet(); var mappingFragment = new StorageMappingFragment( tableSet, new StorageEntityTypeMapping( new StorageEntitySetMapping( new EntitySet(), new StorageEntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false); Assert.Same(tableSet, mappingFragment.TableSet); tableSet = new EntitySet(); mappingFragment.TableSet = tableSet; Assert.Same(tableSet, mappingFragment.TableSet); }
public void Can_get_table() { var table = new EntityType("E", "N", DataSpace.CSpace); var tableSet = new EntitySet("ES", null, null, null, table); var mappingFragment = new StorageMappingFragment( tableSet, new StorageEntityTypeMapping( new StorageEntitySetMapping( new EntitySet(), new StorageEntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false); Assert.Same(table, mappingFragment.Table); }
/// <summary> /// Add a fragment mapping as child of this type mapping /// </summary> /// <param name="fragment"> </param> internal void AddFragment(StorageMappingFragment fragment) { DebugCheck.NotNull(fragment); m_fragments.Add(fragment); }
public void Can_add_and_remove_column_conditions() { var mappingFragment = new StorageMappingFragment( new EntitySet(), new StorageEntityTypeMapping( new StorageEntitySetMapping( new EntitySet(), new StorageEntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false); Assert.Empty(mappingFragment.ColumnConditions); var conditionPropertyMapping = new StorageConditionPropertyMapping(null, new EdmProperty("C"), 42, null); mappingFragment.AddConditionProperty(conditionPropertyMapping); Assert.Same(conditionPropertyMapping, mappingFragment.ColumnConditions.Single()); mappingFragment.RemoveConditionProperty(conditionPropertyMapping); Assert.Empty(mappingFragment.ColumnConditions); }
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); }
internal void WriteMappingFragmentElement(StorageMappingFragment mappingFragment) { DebugCheck.NotNull(mappingFragment); _xmlWriter.WriteStartElement(StorageMslConstructs.MappingFragmentElement); _xmlWriter.WriteAttributeString( StorageMslConstructs.MappingFragmentStoreEntitySetAttribute, mappingFragment.TableSet.Name); foreach (var propertyMapping in mappingFragment.Properties) { WritePropertyMapping(propertyMapping); } foreach (var conditionColumn in mappingFragment.ColumnConditions) { WriteConditionElement(conditionColumn); } _xmlWriter.WriteEndElement(); }
private void ConfigureDefaultDiscriminator( EntityType entityType, StorageMappingFragment fragment, bool isSharingTableWithBase) { if ((entityType.BaseType != null && !isSharingTableWithBase) || ValueConditions.Any() || NullabilityConditions.Any()) { var discriminator = fragment.RemoveDefaultDiscriminatorCondition(); if (discriminator != null && entityType.BaseType != null) { discriminator.Nullable = true; } } }
private static void MoveDefaultDiscriminator( StorageMappingFragment fromFragment, StorageMappingFragment toFragment) { var discriminatorColumn = fromFragment.GetDefaultDiscriminator(); if (discriminatorColumn != null) { var discriminator = fromFragment.ColumnConditions.SingleOrDefault( cc => cc.ColumnProperty == discriminatorColumn); if (discriminator != null) { fromFragment.RemoveDefaultDiscriminatorAnnotation(); fromFragment.RemoveConditionProperty(discriminator); toFragment.AddDiscriminatorCondition(discriminator.ColumnProperty, discriminator.Value); toFragment.SetDefaultDiscriminator(discriminator.ColumnProperty); } } }
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); }
private EntityType FindOrCreateTargetTable( DbDatabaseMapping databaseMapping, StorageMappingFragment fragment, EntityType entityType, EntityType fromTable, out bool isTableSharing) { EntityType toTable; isTableSharing = false; if (TableName == null) { toTable = fragment.Table; } else { toTable = databaseMapping.Database.FindTableByName(TableName); if (toTable == null) { if (entityType.BaseType == null) { // Rule: base type's always own the fragment's initial table toTable = fragment.Table; } else { toTable = databaseMapping.Database.AddTable(TableName.Name, fromTable); } } // Validate this table can be used and update as needed if it is isTableSharing = UpdateColumnNamesForTableSharing(databaseMapping, entityType, toTable, fragment); fragment.TableSet = databaseMapping.Database.GetEntitySet(toTable); toTable.SetTableName(TableName); } return toTable; }
private void ConfigureConditions( DbDatabaseMapping databaseMapping, EntityType entityType, StorageMappingFragment fragment, DbProviderManifest providerManifest) { if (ValueConditions.Any() || NullabilityConditions.Any()) { fragment.ClearConditions(); foreach (var condition in ValueConditions) { condition.Configure(databaseMapping, fragment, entityType, providerManifest); } foreach (var condition in NullabilityConditions) { condition.Configure(databaseMapping, fragment, entityType); } } }
private static bool UpdateColumnNamesForTableSharing( DbDatabaseMapping databaseMapping, EntityType entityType, EntityType toTable, StorageMappingFragment fragment) { // Validate: this table can be used only if: // 1. The table is not used by any other type // 2. The table is used only by types in the same type hierarchy (TPH) // 3. There is a 1:1 relationship and the PK count and types match (Table Splitting) var typesSharingTable = FindAllTypesUsingTable(databaseMapping, toTable); var associationsToSharedTable = new Dictionary<EntityType, List<AssociationType>>(); foreach (var candidateType in typesSharingTable) { var oneToOneAssocations = FindAllOneToOneFKAssociationTypes( databaseMapping.Model, entityType, candidateType); var rootType = candidateType.GetRootType(); if (!associationsToSharedTable.ContainsKey(rootType)) { associationsToSharedTable.Add(rootType, oneToOneAssocations.ToList()); } else { associationsToSharedTable[rootType].AddRange(oneToOneAssocations); } } foreach (var candidateTypePair in associationsToSharedTable) { // Check if these types are in a TPH hierarchy if (candidateTypePair.Key != entityType.GetRootType() && candidateTypePair.Value.Count == 0) { var tableName = toTable.GetTableName(); throw Error.EntityMappingConfiguration_InvalidTableSharing( entityType.Name, candidateTypePair.Key.Name, tableName != null ? tableName.Name : databaseMapping.Database.GetEntitySet(toTable).Table); } } var allAssociations = associationsToSharedTable.Values.SelectMany(l => l); if (allAssociations.Any()) { var principalKeyNamesType = toTable.GetKeyNamesType(); if (principalKeyNamesType == null) { // grab a candidate var association = allAssociations.First(); principalKeyNamesType = association.Constraint.FromRole.GetEntityType(); if (allAssociations.All(x => x.Constraint.FromRole.GetEntityType() == principalKeyNamesType)) { toTable.SetKeyNamesType(principalKeyNamesType); } } // rename the columns in the fragment to match the principal keys var principalKeys = principalKeyNamesType.KeyProperties().ToArray(); var i = 0; foreach (var k in entityType.KeyProperties()) { var dependentColumn = fragment.ColumnMappings.Single(pm => pm.PropertyPath.First() == k).ColumnProperty; dependentColumn.Name = principalKeys[i].Name; i++; } return true; } return false; }
public static string GetIdentity(StorageMappingFragment mapping) { return(mapping.TableSet.Identity); }