public static string GetIdentity(StorageComplexTypeMapping mapping) { var properties = mapping.AllProperties.Select(it => GetIdentity(it)) .OrderBy(it => it, StringComparer.Ordinal); var types = mapping.Types.Select(it => it.Identity) .OrderBy(it => it, StringComparer.Ordinal); var isOfTypes = mapping.IsOfTypes.Select(it => it.Identity) .OrderBy(it => it, StringComparer.Ordinal); return(string.Join(",", properties.Concat(types).Concat(isOfTypes))); }
public void Can_add_and_remove_properties() { var complexTypeMapping = new StorageComplexTypeMapping(false); var scalarPropertyMapping = new StorageScalarPropertyMapping(new EdmProperty("P"), new EdmProperty("C")); Assert.Empty(complexTypeMapping.Properties); complexTypeMapping.AddProperty(scalarPropertyMapping); Assert.Same(scalarPropertyMapping, complexTypeMapping.Properties.Single()); complexTypeMapping.RemoveProperty(scalarPropertyMapping); Assert.Empty(complexTypeMapping.Properties); }
protected virtual void Visit(StorageComplexTypeMapping storageComplexTypeMapping) { foreach (var property in GetSequence(storageComplexTypeMapping.AllProperties, it => IdentityHelper.GetIdentity(it))) { Visit(property); } foreach (var type in GetSequence(storageComplexTypeMapping.IsOfTypes, it => it.Identity)) { Visit(type); } foreach (var type in GetSequence(storageComplexTypeMapping.Types, it => it.Identity)) { Visit(type); } }
protected virtual void Visit(StorageComplexTypeMapping storageComplexTypeMapping) { foreach (var property in storageComplexTypeMapping.AllProperties) { Visit(property); } foreach (var type in storageComplexTypeMapping.IsOfTypes) { Visit(type); } foreach (var type in storageComplexTypeMapping.Types) { Visit(type); } }
protected override void Visit(StorageComplexTypeMapping storageComplexTypeMapping) { int index; if (!AddObjectToSeenListAndHashBuilder(storageComplexTypeMapping, out index)) { return; } AddObjectStartDumpToHashBuilder(storageComplexTypeMapping, index); #region Inner data visit base.Visit(storageComplexTypeMapping); #endregion AddObjectEndDumpToHashBuilder(); }
public static void GetIdentity_of_StorageComplexTypeMapping_returns_expected_value() { var complexType1 = new ComplexType("CT1", "N", DataSpace.CSpace); var complexType2 = new ComplexType("CT2", "N", DataSpace.CSpace); var complexType3 = new ComplexType("CT3", "N", DataSpace.CSpace); var complexType4 = new ComplexType("CT4", "N", DataSpace.CSpace); var property1 = new EdmProperty("A", TypeUsage.Create(complexType1)); var property2 = new EdmProperty("B", TypeUsage.Create(complexType2)); var propertyMapping1 = new StorageComplexPropertyMapping(property1); var propertyMapping2 = new StorageComplexPropertyMapping(property2); var mapping = new StorageComplexTypeMapping(false); mapping.AddType(complexType2); mapping.AddType(complexType1); mapping.AddIsOfType(complexType4); mapping.AddIsOfType(complexType3); mapping.AddProperty(propertyMapping2); mapping.AddProperty(propertyMapping1); Assert.Equal("ComplexProperty(Identity=A),ComplexProperty(Identity=B),N.CT1,N.CT2,N.CT3,N.CT4", BaseMetadataMappingVisitor.IdentityHelper.GetIdentity(mapping)); }
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 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; } }
/// <summary> /// Add type mapping as a child under this Property Mapping /// </summary> /// <param name="typeMapping"> </param> internal void AddTypeMapping(StorageComplexTypeMapping typeMapping) { m_typeMappings.Add(typeMapping); }
/// <summary> /// Add type mapping as a child under this Property Mapping /// </summary> internal void AddTypeMapping(StorageComplexTypeMapping typeMapping) { m_typeMappings.Add(typeMapping); }