public void Can_create_mapping_and_get_association_end() { var associationEnd = new AssociationEndMember("E", new EntityType("E", "N", DataSpace.CSpace)); var mapping = new EndPropertyMapping(associationEnd); Assert.Same(associationEnd, mapping.AssociationEnd); }
public void Can_set_and_get_end_member() { var endPropertyMapping = new EndPropertyMapping(); Assert.Null(endPropertyMapping.AssociationEnd); var endMember = new AssociationEndMember("E", new EntityType("E", "N", DataSpace.CSpace)); endPropertyMapping.AssociationEnd = endMember; Assert.Same(endMember, endPropertyMapping.AssociationEnd); }
public static void GetIdentity_of_StorageEndPropertyMapping_returns_expected_value() { var entityType = new EntityType("ET", "N", DataSpace.CSpace); PropertyMapping mapping = new EndPropertyMapping() { AssociationEnd = new AssociationEndMember("AEM", entityType) }; Assert.Equal("EndProperty(Identity=AEM)", BaseMetadataMappingVisitor.IdentityHelper.GetIdentity(mapping)); }
public void Can_get_property_mappings() { var endPropertyMapping = new EndPropertyMapping(); Assert.Empty(endPropertyMapping.PropertyMappings); var scalarPropertyMapping = new ScalarPropertyMapping(new EdmProperty("P"), new EdmProperty("C", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace }))); endPropertyMapping.AddPropertyMapping(scalarPropertyMapping); Assert.Same(scalarPropertyMapping, endPropertyMapping.PropertyMappings.Single()); }
public void Cannot_set_target_end_mapping_when_read_only() { var entitySet = new EntitySet(); var associationSet = new AssociationSet("AS", new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace)); var associationSetMapping = new AssociationSetMapping(associationSet, entitySet); var targetEndMapping = new EndPropertyMapping(); associationSetMapping.SetReadOnly(); Assert.Equal( Strings.OperationOnReadOnlyItem, Assert.Throws <InvalidOperationException>( () => (associationSetMapping.TargetEndMapping = targetEndMapping)).Message); }
public void Can_get_property_mappings() { var endPropertyMapping = new EndPropertyMapping(); Assert.Empty(endPropertyMapping.Properties); var scalarPropertyMapping = new ScalarPropertyMapping(new EdmProperty("P"), new EdmProperty("C", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace }))); endPropertyMapping.AddProperty(scalarPropertyMapping); Assert.Same(scalarPropertyMapping, endPropertyMapping.Properties.Single()); }
public void Cannot_add_property_when_read_only() { var associationEnd = new AssociationEndMember("E", new EntityType("E", "N", DataSpace.CSpace)); var mapping = new EndPropertyMapping(associationEnd); mapping.SetReadOnly(); Assert.True(mapping.IsReadOnly); var scalarPropertyMapping = new ScalarPropertyMapping(new EdmProperty("P"), new EdmProperty("C", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace }))); Assert.Equal( Strings.OperationOnReadOnlyItem, Assert.Throws<InvalidOperationException>( () => mapping.AddPropertyMapping(scalarPropertyMapping)).Message); }
public void SetReadOnly_is_called_on_child_mapping_items() { var associationEnd = new AssociationEndMember("E", new EntityType("E", "N", DataSpace.CSpace)); var mapping = new EndPropertyMapping(associationEnd); var scalarPropertyMapping = new ScalarPropertyMapping(new EdmProperty("P"), new EdmProperty("C", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace }))); mapping.AddProperty(scalarPropertyMapping); Assert.False(scalarPropertyMapping.IsReadOnly); mapping.SetReadOnly(); Assert.True(scalarPropertyMapping.IsReadOnly); }
public void Cannot_remove_property_when_read_only() { var associationEnd = new AssociationEndMember("E", new EntityType("E", "N", DataSpace.CSpace)); var mapping = new EndPropertyMapping(associationEnd); var scalarPropertyMapping = new ScalarPropertyMapping(new EdmProperty("P"), new EdmProperty("C", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace }))); mapping.AddProperty(scalarPropertyMapping); mapping.SetReadOnly(); Assert.True(mapping.IsReadOnly); Assert.Equal( Strings.OperationOnReadOnlyItem, Assert.Throws <InvalidOperationException>( () => mapping.RemoveProperty(scalarPropertyMapping)).Message); }
public static string GetIdentity(PropertyMapping mapping) { ScalarPropertyMapping mapping1 = mapping as ScalarPropertyMapping; if (mapping1 != null) { return(BaseMetadataMappingVisitor.IdentityHelper.GetIdentity(mapping1)); } ComplexPropertyMapping mapping2 = mapping as ComplexPropertyMapping; if (mapping2 != null) { return(BaseMetadataMappingVisitor.IdentityHelper.GetIdentity(mapping2)); } EndPropertyMapping mapping3 = mapping as EndPropertyMapping; if (mapping3 != null) { return(BaseMetadataMappingVisitor.IdentityHelper.GetIdentity(mapping3)); } return(BaseMetadataMappingVisitor.IdentityHelper.GetIdentity((ConditionPropertyMapping)mapping)); }
public void Can_get_and_set_source_and_target_end_mappings() { var entitySet1 = new EntitySet(); var associationSet = new AssociationSet("AS", new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace)); var associationSetMapping = new AssociationSetMapping(associationSet, entitySet1); Assert.Null(associationSetMapping.SourceEndMapping); Assert.Null(associationSetMapping.TargetEndMapping); var sourceEndMapping = new EndPropertyMapping(); associationSetMapping.SourceEndMapping = sourceEndMapping; Assert.Same(sourceEndMapping, associationSetMapping.SourceEndMapping); var targetEndMapping = new EndPropertyMapping(); associationSetMapping.TargetEndMapping = targetEndMapping; Assert.Same(targetEndMapping, associationSetMapping.TargetEndMapping); }
private void WriteAssociationEndMappingElement(EndPropertyMapping endMapping) { DebugCheck.NotNull(endMapping); _xmlWriter.WriteStartElement(MslConstructs.EndPropertyMappingElement); _xmlWriter.WriteAttributeString(MslConstructs.EndPropertyMappingNameAttribute, endMapping.AssociationEnd.Name); foreach (var propertyMapping in endMapping.PropertyMappings) { WriteScalarPropertyElement( propertyMapping.Property.Name, propertyMapping.Column.Name); } _xmlWriter.WriteEndElement(); }
private IEnumerable<EdmProperty> GenerateIndependentForeignKeyColumns( EntityType principalEntityType, EntityType dependentEntityType, AssociationSetMapping associationSetMapping, EndPropertyMapping 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.AssociationEnd.IsOptional() || (associationEndMapping.AssociationEnd.IsRequired() && dependentEntityType.BaseType != null); foreignKeyColumn.StoreGeneratedPattern = StoreGeneratedPattern.None; yield return foreignKeyColumn; associationEndMapping.AddPropertyMapping(new ScalarPropertyMapping(property, foreignKeyColumn)); if (foreignKeyColumn.Nullable) { associationSetMapping .AddCondition(new IsNullConditionMapping(foreignKeyColumn, false)); } } }
private void GenerateIndependentForeignKeyConstraint( DbDatabaseMapping databaseMapping, EntityType principalEntityType, EntityType dependentEntityType, EntityType dependentTable, AssociationSetMapping associationSetMapping, EndPropertyMapping 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.AssociationEnd.DeleteBehavior != OperationAction.None ? associationEndMapping.AssociationEnd.DeleteBehavior : OperationAction.None }; var principalNavigationProperty = databaseMapping.Model.EntityTypes .SelectMany(e => e.DeclaredNavigationProperties) .SingleOrDefault(n => n.ResultEnd == principalEnd); dependentTable.AddForeignKey(foreignKeyConstraint); foreignKeyConstraint.DependentColumns = GenerateIndependentForeignKeyColumns( principalEntityType, dependentEntityType, associationSetMapping, associationEndMapping, dependentTable, isPrimaryKeyColumn, principalNavigationProperty); }
public void SetReadOnly_is_called_on_child_mapping_items() { var associationEnd = new AssociationEndMember("E", new EntityType("E", "N", DataSpace.CSpace)); var mapping = new EndPropertyMapping(associationEnd); var scalarPropertyMapping = new ScalarPropertyMapping(new EdmProperty("P"), new EdmProperty("C", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace }))); mapping.AddPropertyMapping(scalarPropertyMapping); Assert.False(scalarPropertyMapping.IsReadOnly); mapping.SetReadOnly(); Assert.True(scalarPropertyMapping.IsReadOnly); }
public static string GetIdentity(EndPropertyMapping mapping) { return("EndProperty(Identity=" + mapping.AssociationEnd.Identity + ")"); }
private static EndPropertyMapping BuildEndPropertyMapping( AssociationSetEnd storeSetEnd, SimpleMappingContext mappingContext) { Debug.Assert(storeSetEnd != null, "storeSetEnd != null"); Debug.Assert(mappingContext != null, "mappingContext != null"); var endPropertyMapping = new EndPropertyMapping { AssociationEnd = mappingContext[storeSetEnd].CorrespondingAssociationEndMember }; foreach (EdmProperty storeKeyMember in storeSetEnd.EntitySet.ElementType.KeyMembers) { var modelKeyMember = mappingContext[storeKeyMember]; var storeFkTableMember = GetAssociatedFkColumn(storeSetEnd, storeKeyMember); endPropertyMapping.AddPropertyMapping( new ScalarPropertyMapping(modelKeyMember, storeFkTableMember)); } return endPropertyMapping; }
private static void MoveAssociationSetMappingDependents( AssociationSetMapping associationSetMapping, EndPropertyMapping 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.Column; pm.Column = TableOperations.MoveColumnAndAnyConstraints( associationSetMapping.Table, toTable, oldColumn, useExistingColumns); associationSetMapping.Conditions .Where(cc => cc.Column == oldColumn) .Each(cc => cc.Column = pm.Column); }); associationSetMapping.StoreEntitySet = toSet; }
public void Cannot_set_target_end_mapping_when_read_only() { var entitySet = new EntitySet(); var associationSet = new AssociationSet("AS", new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace)); var associationSetMapping = new AssociationSetMapping(associationSet, entitySet); var targetEndMapping = new EndPropertyMapping(); associationSetMapping.SetReadOnly(); Assert.Equal( Strings.OperationOnReadOnlyItem, Assert.Throws<InvalidOperationException>( () => (associationSetMapping.TargetEndMapping = targetEndMapping)).Message); }