public void WriteAssociationSetMappingElement(StorageAssociationSetMapping associationSetMapping) { DebugCheck.NotNull(associationSetMapping); _xmlWriter.WriteStartElement(StorageMslConstructs.AssociationSetMappingElement); _xmlWriter.WriteAttributeString( StorageMslConstructs.AssociationSetMappingNameAttribute, associationSetMapping.AssociationSet.Name); _xmlWriter.WriteAttributeString( StorageMslConstructs.AssociationSetMappingTypeNameAttribute, _entityTypeNamespace + "." + associationSetMapping.AssociationSet.ElementType.Name); _xmlWriter.WriteAttributeString( StorageMslConstructs.AssociationSetMappingStoreEntitySetAttribute, associationSetMapping.Table.Name); WriteAssociationEndMappingElement(associationSetMapping.SourceEndMapping); WriteAssociationEndMappingElement(associationSetMapping.TargetEndMapping); if (associationSetMapping.ModificationFunctionMapping != null) { WriteModificationFunctionMapping(associationSetMapping.ModificationFunctionMapping); } foreach (var conditionColumn in associationSetMapping.ColumnConditions) { WriteConditionElement(conditionColumn); } _xmlWriter.WriteEndElement(); }
internal override void Configure( StorageAssociationSetMapping associationSetMapping, EdmModel database, PropertyInfo navigationProperty) { DebugCheck.NotNull(associationSetMapping); DebugCheck.NotNull(database); DebugCheck.NotNull(navigationProperty); var table = associationSetMapping.Table; if (_tableName != null) { table.SetTableName(_tableName); table.SetConfiguration(this); } var sourceEndIsPrimaryConfiguration = navigationProperty.IsSameAs( associationSetMapping.SourceEndMapping.EndMember.GetClrPropertyInfo()); ConfigureColumnNames( sourceEndIsPrimaryConfiguration ? _leftKeyColumnNames : _rightKeyColumnNames, associationSetMapping.SourceEndMapping.PropertyMappings.ToList()); ConfigureColumnNames( sourceEndIsPrimaryConfiguration ? _rightKeyColumnNames : _leftKeyColumnNames, associationSetMapping.TargetEndMapping.PropertyMappings.ToList()); }
internal AssociationSetTranslator(StorageAssociationSetMapping setMapping) { if (null != setMapping) { m_mapping = setMapping.ModificationFunctionMapping; } }
public void Configure_should_rename_table_when_table_configured() { var database = new EdmModel(DataSpace.SSpace); var table = database.AddTable("OriginalName"); var associationSetMapping = new StorageAssociationSetMapping( new AssociationSet("AS", new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace)), database.GetEntitySet(table)) .Initialize(); var manyToManyAssociationMappingConfiguration = new ManyToManyAssociationMappingConfiguration(); manyToManyAssociationMappingConfiguration.ToTable("NewName"); var mockPropertyInfo = new MockPropertyInfo(); associationSetMapping.SourceEndMapping.EndMember = new AssociationEndMember("S", new EntityType("E", "N", DataSpace.CSpace)); associationSetMapping.SourceEndMapping.EndMember.SetClrPropertyInfo(mockPropertyInfo); manyToManyAssociationMappingConfiguration.Configure(associationSetMapping, database, mockPropertyInfo); Assert.Equal("NewName", table.GetTableName().Name); Assert.Same(manyToManyAssociationMappingConfiguration, table.GetConfiguration()); }
public void Configure_should_throw_when_incorrect_number_of_columns_configured() { var database = new EdmModel(DataSpace.CSpace); var associationSetMapping = new StorageAssociationSetMapping( new AssociationSet("AS", new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace)), new EntitySet()) .Initialize(); var manyToManyAssociationMappingConfiguration = new ManyToManyAssociationMappingConfiguration(); manyToManyAssociationMappingConfiguration.MapLeftKey("Id1", "Id2"); var mockPropertyInfo = new MockPropertyInfo(); associationSetMapping.SourceEndMapping.EndMember = new AssociationEndMember("S", new EntityType("E", "N", DataSpace.CSpace)); associationSetMapping.SourceEndMapping.EndMember.SetClrPropertyInfo(mockPropertyInfo); Assert.Equal( Strings.IncorrectColumnCount("Id1, Id2"), Assert.Throws<InvalidOperationException>( () => manyToManyAssociationMappingConfiguration.Configure(associationSetMapping, database, mockPropertyInfo)).Message); }
public void Configure_should_rename_columns_when_right_keys_configured() { var database = new EdmModel(DataSpace.CSpace); var associationSetMapping = new StorageAssociationSetMapping( new AssociationSet("AS", new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace)), new EntitySet()) .Initialize(); var column = new EdmProperty("C"); associationSetMapping.TargetEndMapping.AddProperty(new StorageScalarPropertyMapping(new EdmProperty("PK"), column)); var manyToManyAssociationMappingConfiguration = new ManyToManyAssociationMappingConfiguration(); manyToManyAssociationMappingConfiguration.MapRightKey("NewName"); var mockPropertyInfo = new MockPropertyInfo(); associationSetMapping.SourceEndMapping.EndMember = new AssociationEndMember("S", new EntityType("E", "N", DataSpace.CSpace)); associationSetMapping.SourceEndMapping.EndMember.SetClrPropertyInfo(mockPropertyInfo); manyToManyAssociationMappingConfiguration.Configure(associationSetMapping, database, mockPropertyInfo); Assert.Equal("NewName", column.Name); }
private static void MoveAssociationSetMappingDependents( StorageAssociationSetMapping associationSetMapping, StorageEndPropertyMapping dependentMapping, EntitySet toSet, bool useExistingColumns) { DebugCheck.NotNull(associationSetMapping); DebugCheck.NotNull(dependentMapping); DebugCheck.NotNull(toSet); var toTable = toSet.ElementType; dependentMapping.PropertyMappings.Each( pm => { var oldColumn = pm.ColumnProperty; pm.ColumnProperty = TableOperations.MoveColumnAndAnyConstraints( associationSetMapping.Table, toTable, oldColumn, useExistingColumns); associationSetMapping.ColumnConditions .Where(cc => cc.ColumnProperty == oldColumn) .Each(cc => cc.ColumnProperty = pm.ColumnProperty); }); associationSetMapping.StoreEntitySet = toSet; }
public void Configure_should_rename_columns_when_left_keys_configured() { var database = new EdmModel().Initialize(); var associationSetMapping = new StorageAssociationSetMapping( new AssociationSet("AS", new AssociationType()), new EntitySet()) .Initialize(); var column = new EdmProperty("C"); associationSetMapping.SourceEndMapping.AddProperty(new StorageScalarPropertyMapping(new EdmProperty("PK"), column)); var manyToManyAssociationMappingConfiguration = new ManyToManyAssociationMappingConfiguration(); manyToManyAssociationMappingConfiguration.MapLeftKey("NewName"); var mockPropertyInfo = new MockPropertyInfo(); associationSetMapping.SourceEndMapping.EndMember = new AssociationEndMember("S", new EntityType()); associationSetMapping.SourceEndMapping.EndMember.SetClrPropertyInfo(mockPropertyInfo); manyToManyAssociationMappingConfiguration.Configure(associationSetMapping, database, mockPropertyInfo); Assert.Equal("NewName", column.Name); }
internal void Configure( StorageAssociationSetMapping associationSetMapping, DbDatabaseMapping databaseMapping, DbProviderManifest providerManifest) { DebugCheck.NotNull(associationSetMapping); DebugCheck.NotNull(databaseMapping); DebugCheck.NotNull(providerManifest); // We may apply configuration twice from two different NavigationPropertyConfiguration objects, // but that should be okay since they were validated as consistent above. // We still apply twice because each object may have different pieces of the full configuration. if (AssociationMappingConfiguration != null) { // This may replace a configuration previously set, but that's okay since we validated // consistency when processing the configuration above. associationSetMapping.SetConfiguration(this); AssociationMappingConfiguration .Configure(associationSetMapping, databaseMapping.Database, _navigationProperty); } if (_modificationFunctionsConfiguration != null) { if (associationSetMapping.ModificationFunctionMapping == null) { new ModificationFunctionMappingGenerator(providerManifest) .Generate(associationSetMapping, databaseMapping); } _modificationFunctionsConfiguration.Configure(associationSetMapping.ModificationFunctionMapping); } }
private static bool TryGetWithRelationship( StorageAssociationSetMapping colocatedAssociationSetMap, EntitySetBase thisExtent, MemberPath sRootNode, ref List <SlotInfo> foreignKeySlots, out WithRelationship withRelationship) { DebugCheck.NotNull(foreignKeySlots); withRelationship = null; //Get the map for foreign key end var foreignKeyEndMap = GetForeignKeyEndMapFromAssocitionMap(colocatedAssociationSetMap); if (foreignKeyEndMap == null || foreignKeyEndMap.EndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many) { return(false); } var toEnd = (AssociationEndMember)foreignKeyEndMap.EndMember; var fromEnd = MetadataHelper.GetOtherAssociationEnd(toEnd); var toEndEntityType = (EntityType)((RefType)(toEnd.TypeUsage.EdmType)).ElementType; var fromEndEntityType = (EntityType)(((RefType)fromEnd.TypeUsage.EdmType).ElementType); // Get the member path for AssociationSet var associationSet = (AssociationSet)colocatedAssociationSetMap.Set; var prefix = new MemberPath(associationSet, toEnd); // Collect the member paths for edm scalar properties that belong to the target entity key. // These will be used as part of WITH RELATIONSHIP. // Get the key properties from edm type since the query parser depends on the order of key members var propertyMaps = foreignKeyEndMap.Properties.Cast <StorageScalarPropertyMapping>(); var toEndEntityKeyMemberPaths = new List <MemberPath>(); foreach (EdmProperty edmProperty in toEndEntityType.KeyMembers) { var scalarPropertyMaps = propertyMaps.Where(propMap => (propMap.EdmProperty.Equals(edmProperty))); Debug.Assert(scalarPropertyMaps.Count() == 1, "Can't Map the same column multiple times in the same end"); var scalarPropertyMap = scalarPropertyMaps.First(); // Create SlotInfo for Freign Key member that needs to be projected. var sSlot = new MemberProjectedSlot(new MemberPath(sRootNode, scalarPropertyMap.ColumnProperty)); var endMemberKeyPath = new MemberPath(prefix, edmProperty); toEndEntityKeyMemberPaths.Add(endMemberKeyPath); foreignKeySlots.Add(new SlotInfo(true, true, sSlot, endMemberKeyPath)); } // Parent assignable from child: Ensures they are in the same hierarchy. if (thisExtent.ElementType.IsAssignableFrom(fromEndEntityType)) { // Now create the WITH RELATIONSHIP with all the needed info. withRelationship = new WithRelationship( associationSet, fromEnd, fromEndEntityType, toEnd, toEndEntityType, toEndEntityKeyMemberPaths); return(true); } else { return(false); } }
public void Generate(StorageAssociationSetMapping associationSetMapping, DbDatabaseMapping databaseMapping) { DebugCheck.NotNull(associationSetMapping); DebugCheck.NotNull(databaseMapping); var iaFkProperties = GetIndependentFkColumns(associationSetMapping).ToList(); var insertFunctionMapping = GenerateFunctionMapping( ModificationOperator.Insert, associationSetMapping.AssociationSet, associationSetMapping.AssociationSet.ElementType, databaseMapping, Enumerable.Empty <EdmProperty>(), iaFkProperties, new ColumnMappingBuilder[0]); var deleteFunctionMapping = GenerateFunctionMapping( ModificationOperator.Delete, associationSetMapping.AssociationSet, associationSetMapping.AssociationSet.ElementType, databaseMapping, Enumerable.Empty <EdmProperty>(), iaFkProperties, new ColumnMappingBuilder[0]); associationSetMapping.ModificationFunctionMapping = new StorageAssociationSetModificationFunctionMapping( associationSetMapping.AssociationSet, deleteFunctionMapping, insertFunctionMapping); }
public void Initialize_should_initialize_ends() { var associationSetMapping = new StorageAssociationSetMapping(new AssociationSet("AS", new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace)), new EntitySet()).Initialize(); Assert.NotNull(associationSetMapping.SourceEndMapping); Assert.NotNull(associationSetMapping.TargetEndMapping); }
public void Initialize_should_initialize_ends() { var associationSetMapping = new StorageAssociationSetMapping(new AssociationSet("AS", new AssociationType()), new EntitySet()).Initialize(); Assert.NotNull(associationSetMapping.SourceEndMapping); Assert.NotNull(associationSetMapping.TargetEndMapping); }
public static StorageAssociationSetMapping Initialize(this StorageAssociationSetMapping associationSetMapping) { DebugCheck.NotNull(associationSetMapping); associationSetMapping.SourceEndMapping = new StorageEndPropertyMapping(null); associationSetMapping.TargetEndMapping = new StorageEndPropertyMapping(null); return(associationSetMapping); }
public void Can_get_and_set_configuration_annotation() { var associationSetMapping = new StorageAssociationSetMapping(new AssociationSet("AS", new AssociationType()), new EntitySet()); associationSetMapping.SetConfiguration(42); Assert.Equal(42, associationSetMapping.GetConfiguration()); }
public void Can_get_and_set_configuration_annotation() { var associationSetMapping = new StorageAssociationSetMapping(new AssociationSet("AS", new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace)), new EntitySet()); associationSetMapping.SetConfiguration(42); Assert.Equal(42, associationSetMapping.GetConfiguration()); }
private void GenerateIndependentForeignKeyConstraint( DbDatabaseMapping databaseMapping, EntityType principalEntityType, EntityType dependentEntityType, EntityType dependentTable, StorageAssociationSetMapping associationSetMapping, StorageEndPropertyMapping associationEndMapping, string name, AssociationEndMember principalEnd, bool isPrimaryKeyColumn = false) { DebugCheck.NotNull(databaseMapping); DebugCheck.NotNull(principalEntityType); DebugCheck.NotNull(dependentTable); DebugCheck.NotNull(associationEndMapping); DebugCheck.NotEmpty(name); var principalTable = GetEntityTypeMappingInHierarchy(databaseMapping, principalEntityType) .MappingFragments .Single() .Table; var foreignKeyConstraint = new ForeignKeyBuilder(databaseMapping.Database, name) { PrincipalTable = principalTable, DeleteAction = associationEndMapping.EndMember.DeleteBehavior != OperationAction.None ? associationEndMapping.EndMember.DeleteBehavior : OperationAction.None }; var principalNavigationProperty = databaseMapping.Model.GetEntityTypes() .SelectMany(e => e.DeclaredNavigationProperties) .SingleOrDefault(n => n.ResultEnd == principalEnd); dependentTable.AddForeignKey(foreignKeyConstraint); foreignKeyConstraint.DependentColumns = GenerateIndependentForeignKeyColumns( principalEntityType, dependentEntityType, associationSetMapping, associationEndMapping, dependentTable, isPrimaryKeyColumn, principalNavigationProperty); }
private IEnumerable <EdmProperty> GenerateIndependentForeignKeyColumns( EntityType principalEntityType, EntityType dependentEntityType, StorageAssociationSetMapping associationSetMapping, StorageEndPropertyMapping associationEndMapping, EntityType dependentTable, bool isPrimaryKeyColumn, NavigationProperty principalNavigationProperty) { DebugCheck.NotNull(principalEntityType); DebugCheck.NotNull(associationEndMapping); DebugCheck.NotNull(dependentTable); foreach (var property in principalEntityType.KeyProperties()) { var columnName = ((principalNavigationProperty != null) ? principalNavigationProperty.Name : principalEntityType.Name) + "_" + property.Name; var foreignKeyColumn = MapTableColumn(property, columnName, false); dependentTable.AddColumn(foreignKeyColumn); if (isPrimaryKeyColumn) { dependentTable.AddKeyMember(foreignKeyColumn); } foreignKeyColumn.Nullable = associationEndMapping.EndMember.IsOptional() || (associationEndMapping.EndMember.IsRequired() && dependentEntityType.BaseType != null); foreignKeyColumn.StoreGeneratedPattern = StoreGeneratedPattern.None; yield return(foreignKeyColumn); associationEndMapping.AddProperty(new StorageScalarPropertyMapping(property, foreignKeyColumn)); if (foreignKeyColumn.Nullable) { associationSetMapping .AddColumnCondition(new StorageConditionPropertyMapping(null, foreignKeyColumn, null, false)); } } }
public static StorageAssociationSetMapping AddAssociationSetMapping( this DbDatabaseMapping databaseMapping, AssociationSet associationSet, EntitySet entitySet) { DebugCheck.NotNull(databaseMapping); DebugCheck.NotNull(associationSet); var associationSetMapping = new StorageAssociationSetMapping(associationSet, entitySet).Initialize(); databaseMapping .EntityContainerMappings .Single() .AddAssociationSetMapping(associationSetMapping); return(associationSetMapping); }
private void WriteAssociationSetMappingElement(StorageAssociationSetMapping set) { _xmlWriter.WriteStartElement(StorageMslConstructs.AssociationSetMappingElement); _xmlWriter.WriteAttributeString(StorageMslConstructs.AssociationSetMappingNameAttribute, set.AssociationSet.Name); _xmlWriter.WriteAttributeString( StorageMslConstructs.AssociationSetMappingTypeNameAttribute, _entityTypeNamespace + "." + set.AssociationSet.ElementType.Name); _xmlWriter.WriteAttributeString(StorageMslConstructs.AssociationSetMappingStoreEntitySetAttribute, set.Table.Name); WriteAssociationEndMappingElement(set.SourceEndMapping); WriteAssociationEndMappingElement(set.TargetEndMapping); foreach (var conditionColumn in set.ColumnConditions) { WriteConditionElement(conditionColumn); } _xmlWriter.WriteEndElement(); }
public void Configure_should_split_key_constraint_when_to_table_configuration() { var database = new EdmModel().DbInitialize(); var sourceTable = database.AddTable("Source"); var principalTable = database.AddTable("P"); var fkColumn = new EdmProperty( "Fk", ProviderRegistry.Sql2008_ProviderManifest.GetStoreType( TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)))); sourceTable.AddColumn(fkColumn); var foreignKeyConstraint = new ForeignKeyBuilder(database, "FK") { PrincipalTable = principalTable }; sourceTable.AddForeignKey(foreignKeyConstraint); foreignKeyConstraint.DependentColumns = new[] { fkColumn }; var targetTable = database.AddTable("Split"); var associationSetMapping = new StorageAssociationSetMapping( new AssociationSet("AS", new AssociationType()), database.GetEntitySet(sourceTable)).Initialize(); associationSetMapping.SourceEndMapping.AddProperty(new StorageScalarPropertyMapping(new EdmProperty("PK"), fkColumn)); var independentAssociationMappingConfiguration = new ForeignKeyAssociationMappingConfiguration(); independentAssociationMappingConfiguration.ToTable("Split"); independentAssociationMappingConfiguration.Configure(associationSetMapping, database, new MockPropertyInfo()); Assert.True(targetTable.Properties.Contains(fkColumn)); Assert.True(targetTable.ForeignKeyBuilders.Contains(foreignKeyConstraint)); Assert.False(sourceTable.Properties.Contains(fkColumn)); Assert.False(sourceTable.ForeignKeyBuilders.Contains(foreignKeyConstraint)); Assert.Same(targetTable, associationSetMapping.Table); }
//Gets the end that is not mapped to the primary key of the table private StorageEndPropertyMapping GetForeignKeyEndMapFromAssocitionMap(StorageAssociationSetMapping colocatedAssociationSetMap, EntitySetBase thisExtent) { StorageMappingFragment mapFragment = colocatedAssociationSetMap.TypeMappings.First().MappingFragments.First(); EntitySet storeEntitySet = (EntitySet)(colocatedAssociationSetMap.StoreEntitySet); IEnumerable <EdmMember> keyProperties = storeEntitySet.ElementType.KeyMembers; //Find the end that's mapped to primary key foreach (StorageEndPropertyMapping endMap in mapFragment.Properties) { IEnumerable <EdmMember> endStoreMembers = endMap.StoreProperties; if (endStoreMembers.SequenceEqual(keyProperties, EqualityComparer <EdmMember> .Default)) { //Return the map for the other end since that is the foreign key end IEnumerable <StorageEndPropertyMapping> otherEnds = mapFragment.Properties.OfType <StorageEndPropertyMapping>().Where(eMap => (!eMap.Equals(endMap))); Debug.Assert(otherEnds.Count() == 1); return(otherEnds.First()); } } //This is probably defensive, but there should be no problem in falling back on the //AssociationSetMap if colocated foreign key is not found for some reason. return(null); }
public void Configure_should_throw_when_configured_table_not_found() { var independentAssociationMappingConfiguration = new ForeignKeyAssociationMappingConfiguration(); independentAssociationMappingConfiguration.ToTable("Split"); var associationSetMapping = new StorageAssociationSetMapping( new AssociationSet("AS", new AssociationType()), new EntitySet()) .Initialize(); var database = new EdmModel().DbInitialize(); Assert.Equal( Strings.TableNotFound("Split"), Assert.Throws <InvalidOperationException>( () => independentAssociationMappingConfiguration .Configure(associationSetMapping, database, new MockPropertyInfo())). Message); }
public void Generate(StorageAssociationSetMapping associationSetMapping, DbDatabaseMapping databaseMapping) { DebugCheck.NotNull(associationSetMapping); DebugCheck.NotNull(databaseMapping); var iaFkProperties = GetIndependentFkColumns(associationSetMapping).ToList(); var sourceEntityType = associationSetMapping.AssociationSet.ElementType.SourceEnd.GetEntityType(); var targetEntityType = associationSetMapping.AssociationSet.ElementType.TargetEnd.GetEntityType(); var functionNamePrefix = sourceEntityType.Name + targetEntityType.Name; var insertFunctionMapping = GenerateFunctionMapping( ModificationOperator.Insert, associationSetMapping.AssociationSet, associationSetMapping.AssociationSet.ElementType, databaseMapping, Enumerable.Empty <EdmProperty>(), iaFkProperties, new ColumnMappingBuilder[0], functionNamePrefix: functionNamePrefix); var deleteFunctionMapping = GenerateFunctionMapping( ModificationOperator.Delete, associationSetMapping.AssociationSet, associationSetMapping.AssociationSet.ElementType, databaseMapping, Enumerable.Empty <EdmProperty>(), iaFkProperties, new ColumnMappingBuilder[0], functionNamePrefix: functionNamePrefix); associationSetMapping.ModificationFunctionMapping = new StorageAssociationSetModificationFunctionMapping( associationSetMapping.AssociationSet, deleteFunctionMapping, insertFunctionMapping); }
private static IEnumerable <Tuple <StorageModificationFunctionMemberPath, EdmProperty> > GetIndependentFkColumns( StorageAssociationSetMapping associationSetMapping) { DebugCheck.NotNull(associationSetMapping); foreach (var propertyMapping in associationSetMapping.SourceEndMapping.PropertyMappings) { yield return (Tuple.Create( new StorageModificationFunctionMemberPath( new EdmMember[] { propertyMapping.EdmProperty, associationSetMapping.SourceEndMapping.EndMember }, associationSetMapping.AssociationSet), propertyMapping.ColumnProperty)); } foreach (var propertyMapping in associationSetMapping.TargetEndMapping.PropertyMappings) { yield return (Tuple.Create( new StorageModificationFunctionMemberPath( new EdmMember[] { propertyMapping.EdmProperty, associationSetMapping.TargetEndMapping.EndMember }, associationSetMapping.AssociationSet), propertyMapping.ColumnProperty)); } }
/// <summary> /// Initialize a translator for the given association set mapping. /// </summary> /// <param name="setMapping"> Association set mapping. </param> /// <returns> Translator. </returns> internal static ModificationFunctionMappingTranslator CreateAssociationSetTranslator( StorageAssociationSetMapping setMapping) { return(new AssociationSetTranslator(setMapping)); }
public void Can_generate_function_mappings_for_many_to_many_association_set_mapping() { var databaseMapping = new DbDatabaseMapping() .Initialize(new EdmModel(DataSpace.CSpace), new EdmModel(DataSpace.SSpace)); var entityType1 = databaseMapping.Model.AddEntityType("E1"); entityType1.Annotations.SetClrType(typeof(string)); databaseMapping.Model.AddEntitySet("E1Set", entityType1); var entityType2 = databaseMapping.Model.AddEntityType("E2"); entityType2.Annotations.SetClrType(typeof(string)); databaseMapping.Model.AddEntitySet("E2Set", entityType2); var entityTypeConfiguration = new EntityTypeConfiguration(typeof(object)); entityTypeConfiguration.MapToStoredProcedures(); entityType1.SetConfiguration(entityTypeConfiguration); entityType2.SetConfiguration(entityTypeConfiguration); var associationSet = databaseMapping.Model.AddAssociationSet( "M2MSet", databaseMapping.Model.AddAssociationType( "M2M", entityType1, RelationshipMultiplicity.Many, entityType2, RelationshipMultiplicity.Many)); var entitySet = new EntitySet("ES", "S", null, null, new EntityType("E", "N", DataSpace.CSpace)); var associationEndMember1 = new AssociationEndMember("Source", new EntityType("E", "N", DataSpace.CSpace)); associationSet.AddAssociationSetEnd(new AssociationSetEnd(entitySet, associationSet, associationEndMember1)); var associationEndMember2 = new AssociationEndMember("Target", new EntityType("E", "N", DataSpace.CSpace)); associationSet.AddAssociationSetEnd(new AssociationSetEnd(entitySet, associationSet, associationEndMember2)); var associationSetMapping = new StorageAssociationSetMapping( associationSet, entitySet) { SourceEndMapping = new StorageEndPropertyMapping() { EndMember = associationEndMember1 }, TargetEndMapping = new StorageEndPropertyMapping() { EndMember = associationEndMember2 } }; associationSetMapping.SourceEndMapping .AddProperty(new StorageScalarPropertyMapping(new EdmProperty("PK"), new EdmProperty("FooId"))); associationSetMapping.TargetEndMapping .AddProperty(new StorageScalarPropertyMapping(new EdmProperty("PK"), new EdmProperty("BarId"))); var functionMappingGenerator = new ModificationFunctionMappingGenerator(ProviderRegistry.Sql2008_ProviderManifest); functionMappingGenerator.Generate(associationSetMapping, databaseMapping); var modificationFunctionMapping = associationSetMapping.ModificationFunctionMapping; Assert.NotNull(modificationFunctionMapping); var functionMapping = modificationFunctionMapping.InsertFunctionMapping; Assert.NotNull(functionMapping); Assert.Equal(2, functionMapping.ParameterBindings.Count); Assert.Null(functionMapping.ResultBindings); var function = functionMapping.Function; Assert.NotNull(function); Assert.Equal("E1E2_Insert", function.Name); Assert.Equal(2, function.Parameters.Count); functionMapping = modificationFunctionMapping.DeleteFunctionMapping; Assert.NotNull(functionMapping); Assert.Equal(2, functionMapping.ParameterBindings.Count); Assert.Null(functionMapping.ResultBindings); function = modificationFunctionMapping.DeleteFunctionMapping.Function; Assert.NotNull(function); Assert.Equal("E1E2_Delete", function.Name); Assert.Equal(2, function.Parameters.Count); }
internal AssociationSetTranslator(StorageAssociationSetMapping setMapping) { if (null != setMapping) { m_mapping = setMapping.ModificationFunctionMapping; } }
/// <summary> /// Initialize a translator for the given association set mapping. /// </summary> /// <param name="setMapping">Association set mapping.</param> /// <returns>Translator.</returns> internal static ModificationFunctionMappingTranslator CreateAssociationSetTranslator( StorageAssociationSetMapping setMapping) { return new AssociationSetTranslator(setMapping); }
public static object GetConfiguration(this StorageAssociationSetMapping associationSetMapping) { DebugCheck.NotNull(associationSetMapping); return(associationSetMapping.Annotations.GetConfiguration()); }
public void WriteAssociationSetMapping_should_write_modification_function_mapping() { var fixture = new Fixture(); var entityType = new EntityType("E", "N", DataSpace.CSpace); var entitySet = new EntitySet("ES", "S", null, null, entityType); new EntityContainer("EC", DataSpace.SSpace).AddEntitySetBase(entitySet); var associationSet = new AssociationSet("AS", new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace)); var associationEndMember1 = new AssociationEndMember("Source", new EntityType("E", "N", DataSpace.CSpace)); associationSet.AddAssociationSetEnd(new AssociationSetEnd(entitySet, associationSet, associationEndMember1)); var associationEndMember2 = new AssociationEndMember("Target", new EntityType("E", "N", DataSpace.CSpace)); associationSet.AddAssociationSetEnd(new AssociationSetEnd(entitySet, associationSet, associationEndMember2)); var storageModificationFunctionMapping = new StorageModificationFunctionMapping( associationSet, associationSet.ElementType, new EdmFunction("F", "N", DataSpace.SSpace, new EdmFunctionPayload()), new[] { new StorageModificationFunctionParameterBinding( new FunctionParameter( "P", TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32)), ParameterMode.In), new StorageModificationFunctionMemberPath( new EdmMember[] { new EdmProperty("K"), associationEndMember1 }, associationSet), true), new StorageModificationFunctionParameterBinding( new FunctionParameter( "P", TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32)), ParameterMode.In), new StorageModificationFunctionMemberPath( new EdmMember[] { new EdmProperty("K"), associationEndMember2 }, associationSet), false) }, null, null); var associationSetMapping = new StorageAssociationSetMapping( associationSet, entitySet) { SourceEndMapping = new StorageEndPropertyMapping { EndMember = associationEndMember1 }, TargetEndMapping = new StorageEndPropertyMapping { EndMember = associationEndMember2 }, ModificationFunctionMapping = new StorageAssociationSetModificationFunctionMapping( associationSet, storageModificationFunctionMapping, storageModificationFunctionMapping) }; fixture.Writer.WriteAssociationSetMappingElement(associationSetMapping); Assert.Equal( @"<AssociationSetMapping Name=""AS"" TypeName="".A"" StoreEntitySet=""E""> <EndProperty Name=""Source"" /> <EndProperty Name=""Target"" /> <ModificationFunctionMapping> <InsertFunction FunctionName=""N.F""> <EndProperty Name=""Source""> <ScalarProperty Name=""K"" ParameterName=""P"" Version=""Current"" /> </EndProperty> <EndProperty Name=""Target""> <ScalarProperty Name=""K"" ParameterName=""P"" Version=""Original"" /> </EndProperty> </InsertFunction> <DeleteFunction FunctionName=""N.F""> <EndProperty Name=""Source""> <ScalarProperty Name=""K"" ParameterName=""P"" Version=""Current"" /> </EndProperty> <EndProperty Name=""Target""> <ScalarProperty Name=""K"" ParameterName=""P"" Version=""Original"" /> </EndProperty> </DeleteFunction> </ModificationFunctionMapping> </AssociationSetMapping>", fixture.ToString()); }
public static void SetConfiguration(this StorageAssociationSetMapping associationSetMapping, object configuration) { DebugCheck.NotNull(associationSetMapping); associationSetMapping.Annotations.SetConfiguration(configuration); }