Esempio n. 1
0
 public void AddProperty(StorageEndPropertyMapping mapping)
 {
     if (SingleFragment != null)
     {
         SingleFragment.AddProperty(mapping);
     }
 }
Esempio n. 2
0
        public static void GetIdentity_of_StorageEndPropertyMapping_returns_expected_value()
        {
            var entityType = new EntityType("ET", "N", DataSpace.CSpace);
            StoragePropertyMapping mapping = new StorageEndPropertyMapping()
            {
                EndMember = new AssociationEndMember("AEM", entityType)
            };

            Assert.Equal("EndProperty(Identity=AEM)",
                         BaseMetadataMappingVisitor.IdentityHelper.GetIdentity(mapping));
        }
        public void Can_set_and_get_end_member()
        {
            var endPropertyMapping = new StorageEndPropertyMapping();

            Assert.Null(endPropertyMapping.EndMember);

            var endMember = new AssociationEndMember("E", new EntityType("E", "N", DataSpace.CSpace));
            endPropertyMapping.EndMember = endMember;

            Assert.Same(endMember, endPropertyMapping.EndMember);
        }
        public void Can_set_and_get_end_member()
        {
            var endPropertyMapping = new StorageEndPropertyMapping();

            Assert.Null(endPropertyMapping.EndMember);

            var endMember = new AssociationEndMember("E", new EntityType("E", "N", DataSpace.CSpace));

            endPropertyMapping.EndMember = endMember;

            Assert.Same(endMember, endPropertyMapping.EndMember);
        }
        public void Can_get_property_mappings()
        {
            var endPropertyMapping = new StorageEndPropertyMapping(new EdmProperty("P"));

            Assert.Empty(endPropertyMapping.PropertyMappings);

            var scalarPropertyMapping 
                = new StorageScalarPropertyMapping(new EdmProperty("P"), new EdmProperty("C"));

            endPropertyMapping.AddProperty(scalarPropertyMapping);

            Assert.Same(scalarPropertyMapping, endPropertyMapping.PropertyMappings.Single());
        }
        public void Can_get_property_mappings()
        {
            var endPropertyMapping = new StorageEndPropertyMapping(new EdmProperty("P"));

            Assert.Empty(endPropertyMapping.PropertyMappings);

            var scalarPropertyMapping
                = new StorageScalarPropertyMapping(new EdmProperty("P"), new EdmProperty("C"));

            endPropertyMapping.AddProperty(scalarPropertyMapping);

            Assert.Same(scalarPropertyMapping, endPropertyMapping.PropertyMappings.Single());
        }
        public void Can_get_and_set_source__and_target_end_mappings()
        {
            var entitySet1 = new EntitySet();
            var associationSet = new AssociationSet("AS", new AssociationType());

            var associationSetMapping
                = new StorageAssociationSetMapping(associationSet, entitySet1);

            Assert.Null(associationSetMapping.SourceEndMapping);
            Assert.Null(associationSetMapping.TargetEndMapping);

            var sourceEndMapping = new StorageEndPropertyMapping(new EdmProperty("P"));

            associationSetMapping.SourceEndMapping = sourceEndMapping;

            Assert.Same(sourceEndMapping, associationSetMapping.SourceEndMapping);

            var targetEndMapping = new StorageEndPropertyMapping(new EdmProperty("P"));

            associationSetMapping.TargetEndMapping = targetEndMapping;

            Assert.Same(targetEndMapping, associationSetMapping.TargetEndMapping);
        }
        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 StorageAssociationSetMapping(associationSet, entitySet1);

            Assert.Null(associationSetMapping.SourceEndMapping);
            Assert.Null(associationSetMapping.TargetEndMapping);

            var sourceEndMapping = new StorageEndPropertyMapping();

            associationSetMapping.SourceEndMapping = sourceEndMapping;

            Assert.Same(sourceEndMapping, associationSetMapping.SourceEndMapping);

            var targetEndMapping = new StorageEndPropertyMapping();

            associationSetMapping.TargetEndMapping = targetEndMapping;

            Assert.Same(targetEndMapping, associationSetMapping.TargetEndMapping);
        }
        public void Can_get_and_set_source__and_target_end_mappings()
        {
            var entitySet1     = new EntitySet();
            var associationSet = new AssociationSet("AS", new AssociationType());

            var associationSetMapping
                = new StorageAssociationSetMapping(associationSet, entitySet1);

            Assert.Null(associationSetMapping.SourceEndMapping);
            Assert.Null(associationSetMapping.TargetEndMapping);

            var sourceEndMapping = new StorageEndPropertyMapping(new EdmProperty("P"));

            associationSetMapping.SourceEndMapping = sourceEndMapping;

            Assert.Same(sourceEndMapping, associationSetMapping.SourceEndMapping);

            var targetEndMapping = new StorageEndPropertyMapping(new EdmProperty("P"));

            associationSetMapping.TargetEndMapping = targetEndMapping;

            Assert.Same(targetEndMapping, associationSetMapping.TargetEndMapping);
        }
        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 StorageAssociationSetMapping(associationSet, entitySet1);

            Assert.Null(associationSetMapping.SourceEndMapping);
            Assert.Null(associationSetMapping.TargetEndMapping);

            var sourceEndMapping = new StorageEndPropertyMapping();

            associationSetMapping.SourceEndMapping = sourceEndMapping;

            Assert.Same(sourceEndMapping, associationSetMapping.SourceEndMapping);

            var targetEndMapping = new StorageEndPropertyMapping();

            associationSetMapping.TargetEndMapping = targetEndMapping;

            Assert.Same(targetEndMapping, associationSetMapping.TargetEndMapping);
        }
 public void AddProperty(StorageEndPropertyMapping mapping)
 {
     if (SingleFragment != null)
     {
         SingleFragment.AddProperty(mapping);
     }
 }
        private void WriteAssociationEndMappingElement(StorageEndPropertyMapping endMapping)
        {
            DebugCheck.NotNull(endMapping);

            _xmlWriter.WriteStartElement(StorageMslConstructs.EndPropertyMappingElement);
            _xmlWriter.WriteAttributeString(StorageMslConstructs.EndPropertyMappingNameAttribute, endMapping.EndMember.Name);

            foreach (var propertyMapping in endMapping.PropertyMappings)
            {
                WriteScalarPropertyElement(
                    propertyMapping.EdmProperty,
                    propertyMapping.ColumnProperty);
            }

            _xmlWriter.WriteEndElement();
        }
        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));
                }
            }
        }
        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.EntityTypes
                                 .SelectMany(e => e.DeclaredNavigationProperties)
                                 .SingleOrDefault(n => n.ResultEnd == principalEnd);

            dependentTable.AddForeignKey(foreignKeyConstraint);

            foreignKeyConstraint.DependentColumns = GenerateIndependentForeignKeyColumns(
                principalEntityType,
                dependentEntityType,
                associationSetMapping,
                associationEndMapping,
                dependentTable,
                isPrimaryKeyColumn,
                principalNavigationProperty);
        }
        public static void GetIdentity_of_StorageEndPropertyMapping_returns_expected_value()
        {
            var entityType = new EntityType("ET", "N", DataSpace.CSpace);
            StoragePropertyMapping mapping = new StorageEndPropertyMapping()
            {
                EndMember = new AssociationEndMember("AEM", entityType)
            };

            Assert.Equal("EndProperty(Identity=AEM)",
                BaseMetadataMappingVisitor.IdentityHelper.GetIdentity(mapping));
        }
        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 static string GetIdentity(StorageEndPropertyMapping mapping)
 {
     return("EndProperty(Identity=" + mapping.EndMember.Identity + ")");
 }