예제 #1
0
        public void Can_get_and_set_dependent_columns_and_multiplicities_assigned()
        {
            var database = new EdmModel(DataSpace.SSpace);

            var foreignKeyBuilder = new ForeignKeyBuilder(database, "FK");

            var table = database.AddTable("T");

            foreignKeyBuilder.PrincipalTable = table;
            foreignKeyBuilder.SetOwner(table);

            var property = EdmProperty.CreatePrimitive("K", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            foreignKeyBuilder.DependentColumns = new[] { property };

            Assert.Equal(1, foreignKeyBuilder.DependentColumns.Count());

            var associationType = database.GetAssociationType("FK");

            Assert.NotNull(associationType.Constraint);
            Assert.Same(property, associationType.Constraint.ToProperties.Single());
            Assert.Same(associationType.SourceEnd, associationType.Constraint.FromRole);
            Assert.Same(associationType.TargetEnd, associationType.Constraint.ToRole);
            Assert.Equal(RelationshipMultiplicity.Many, associationType.TargetEnd.RelationshipMultiplicity);
            Assert.Equal(RelationshipMultiplicity.ZeroOrOne, associationType.SourceEnd.RelationshipMultiplicity);

            property.Nullable = false;

            foreignKeyBuilder.DependentColumns = new[] { property };

            Assert.Equal(RelationshipMultiplicity.One, associationType.SourceEnd.RelationshipMultiplicity);
        }
        public void Can_set_owner_and_corresponding_association_added_to_model()
        {
            var database = new EdmModel(DataSpace.SSpace);

            var foreignKeyBuilder = new ForeignKeyBuilder(database, "FK");

            var principalTable = database.AddTable("P");

            foreignKeyBuilder.PrincipalTable = principalTable;

            var dependentTable = database.AddTable("D");

            foreignKeyBuilder.SetOwner(dependentTable);

            var associationType = database.GetAssociationType("FK");

            Assert.NotNull(associationType);
            Assert.NotNull(associationType.SourceEnd);
            Assert.NotNull(associationType.TargetEnd);
            Assert.Same(principalTable, associationType.SourceEnd.GetEntityType());
            Assert.Equal("P", associationType.SourceEnd.Name);
            Assert.Same(dependentTable, associationType.TargetEnd.GetEntityType());
            Assert.Equal("D", associationType.TargetEnd.Name);

            var associationSet = database.GetAssociationSet(associationType);

            Assert.NotNull(associationSet);
            Assert.NotNull(associationSet.SourceSet);
            Assert.NotNull(associationSet.TargetSet);
            
        }
예제 #3
0
        public void Can_set_owner_and_corresponding_association_added_to_model()
        {
            var database = new EdmModel(DataSpace.SSpace);

            var foreignKeyBuilder = new ForeignKeyBuilder(database, "FK");

            var principalTable = database.AddTable("P");

            foreignKeyBuilder.PrincipalTable = principalTable;

            var dependentTable = database.AddTable("D");

            foreignKeyBuilder.SetOwner(dependentTable);

            var associationType = database.GetAssociationType("FK");

            Assert.NotNull(associationType);
            Assert.NotNull(associationType.SourceEnd);
            Assert.NotNull(associationType.TargetEnd);
            Assert.Same(principalTable, associationType.SourceEnd.GetEntityType());
            Assert.Equal("P", associationType.SourceEnd.Name);
            Assert.Same(dependentTable, associationType.TargetEnd.GetEntityType());
            Assert.Equal("D", associationType.TargetEnd.Name);

            var associationSet = database.GetAssociationSet(associationType);

            Assert.NotNull(associationSet);
            Assert.NotNull(associationSet.SourceSet);
            Assert.NotNull(associationSet.TargetSet);
        }
예제 #4
0
        public void Set_principal_table_when_self_ref_should_differentiate_target_end_name()
        {
            var database
                = new EdmModel
                {
                Version = 3.0
                }.DbInitialize();
            var foreignKeyBuilder = new ForeignKeyBuilder(database, "FK");

            var table = new EntityType("T", XmlConstants.TargetNamespace_3, DataSpace.SSpace);

            foreignKeyBuilder.PrincipalTable = new EntityType("P", XmlConstants.TargetNamespace_3, DataSpace.SSpace);
            foreignKeyBuilder.SetOwner(table);

            var associationType = database.GetAssociationType("FK");

            Assert.Equal("P", associationType.SourceEnd.Name);
            Assert.Equal("T", associationType.TargetEnd.Name);

            foreignKeyBuilder.PrincipalTable = table;

            Assert.Same(table, associationType.SourceEnd.GetEntityType());
            Assert.Equal("T", associationType.SourceEnd.Name);
            Assert.Same(table, associationType.TargetEnd.GetEntityType());
            Assert.Equal("TSelf", associationType.TargetEnd.Name);
        }
예제 #5
0
        internal void AddForeignKey(ForeignKeyBuilder foreignKeyBuilder)
        {
            DebugCheck.NotNull(foreignKeyBuilder);
            Util.ThrowIfReadOnly(this);

            foreignKeyBuilder.SetOwner(this);

            _foreignKeyBuilders.Add(foreignKeyBuilder);
        }
예제 #6
0
        internal void RemoveForeignKey(ForeignKeyBuilder foreignKeyBuilder)
        {
            DebugCheck.NotNull(foreignKeyBuilder);
            Util.ThrowIfReadOnly(this);

            foreignKeyBuilder.SetOwner(null);

            _foreignKeyBuilders.Remove(foreignKeyBuilder);
        }
예제 #7
0
        internal void RemoveForeignKey(ForeignKeyBuilder foreignKeyBuilder)
        {
            DebugCheck.NotNull(foreignKeyBuilder);
            Util.ThrowIfReadOnly(this);

            foreignKeyBuilder.SetOwner(null);

            _foreignKeyBuilders.Remove(foreignKeyBuilder);
        }
예제 #8
0
        public void AssociationSet_TargetEnd_correct_after_setting_owner()
        {
            var database = new EdmModel(DataSpace.SSpace);

            var foreignKeyBuilder = new ForeignKeyBuilder(database, "FK");

            foreignKeyBuilder.PrincipalTable = database.AddTable("P");
            foreignKeyBuilder.SetOwner(database.AddTable("T"));

            var associationType = database.GetAssociationType("FK");
            var associationSet  = database.GetAssociationSet(associationType);

            Assert.Equal("T", associationType.TargetEnd.Name);
            Assert.Equal("T", associationSet.TargetEnd.Name);

            foreignKeyBuilder.SetOwner(database.AddTable("T1"));

            Assert.Equal("T1", associationType.TargetEnd.Name);
            Assert.Equal("T1", associationSet.TargetEnd.Name);
        }
        public void SetOwner_when_null_should_remove_association_type_from_model()
        {
            var database = new EdmModel(DataSpace.SSpace);

            var foreignKeyBuilder = new ForeignKeyBuilder(database, "FK");

            var principalTable = database.AddTable("P");

            foreignKeyBuilder.PrincipalTable = principalTable;

            var dependentTable = database.AddTable("D");

            foreignKeyBuilder.SetOwner(dependentTable);

            Assert.NotNull(database.GetAssociationType("FK"));

            foreignKeyBuilder.SetOwner(null);

            Assert.Null(database.GetAssociationType("FK"));
        }
예제 #10
0
        public void SetOwner_when_null_should_remove_association_type_from_model()
        {
            var database = new EdmModel(DataSpace.SSpace);

            var foreignKeyBuilder = new ForeignKeyBuilder(database, "FK");

            var principalTable = database.AddTable("P");

            foreignKeyBuilder.PrincipalTable = principalTable;

            var dependentTable = database.AddTable("D");

            foreignKeyBuilder.SetOwner(dependentTable);

            Assert.NotNull(database.GetAssociationType("FK"));

            foreignKeyBuilder.SetOwner(null);

            Assert.Null(database.GetAssociationType("FK"));
        }
예제 #11
0
        public void SetOwner_when_null_should_remove_association_type_from_model()
        {
            var database
                = new EdmModel
                {
                Version = 3.0
                }.DbInitialize();
            var foreignKeyBuilder = new ForeignKeyBuilder(database, "FK");

            var principalTable = new EntityType("P", XmlConstants.TargetNamespace_3, DataSpace.SSpace);

            foreignKeyBuilder.PrincipalTable = principalTable;

            var dependentTable = new EntityType("D", XmlConstants.TargetNamespace_3, DataSpace.SSpace);

            foreignKeyBuilder.SetOwner(dependentTable);

            Assert.NotNull(database.GetAssociationType("FK"));

            foreignKeyBuilder.SetOwner(null);

            Assert.Null(database.GetAssociationType("FK"));
        }
예제 #12
0
        public void Can_get_and_set_delete_action()
        {
            var database = new EdmModel(DataSpace.SSpace);

            var foreignKeyBuilder = new ForeignKeyBuilder(database, "FK");

            var table = database.AddTable("T");

            foreignKeyBuilder.PrincipalTable = table;
            foreignKeyBuilder.SetOwner(table);
            foreignKeyBuilder.DeleteAction = OperationAction.Cascade;

            var associationType = database.GetAssociationType("FK");

            Assert.Equal(OperationAction.Cascade, associationType.SourceEnd.DeleteBehavior);
        }
예제 #13
0
        public void SetOwner_when_self_ref_should_differentiate_target_end_name()
        {
            var database = new EdmModel(DataSpace.SSpace);

            var foreignKeyBuilder = new ForeignKeyBuilder(database, "FK");

            var table = database.AddTable("T");

            foreignKeyBuilder.PrincipalTable = table;
            foreignKeyBuilder.SetOwner(table);

            var associationType = database.GetAssociationType("FK");

            Assert.Same(table, associationType.SourceEnd.GetEntityType());
            Assert.Equal("T", associationType.SourceEnd.Name);
            Assert.Same(table, associationType.TargetEnd.GetEntityType());
            Assert.Equal("TSelf", associationType.TargetEnd.Name);
        }
예제 #14
0
        public void Can_get_and_set_delete_action()
        {
            var database
                = new EdmModel
                {
                Version = 3.0
                }.DbInitialize();
            var foreignKeyBuilder = new ForeignKeyBuilder(database, "FK");

            var table = new EntityType("T", XmlConstants.TargetNamespace_3, DataSpace.SSpace);

            foreignKeyBuilder.PrincipalTable = table;
            foreignKeyBuilder.SetOwner(table);
            foreignKeyBuilder.DeleteAction = OperationAction.Cascade;

            var associationType = database.GetAssociationType("FK");

            Assert.Equal(OperationAction.Cascade, associationType.SourceEnd.DeleteBehavior);
        }
예제 #15
0
        public void SetOwner_when_null_should_remove_association_type_from_model()
        {
            var database
                = new EdmModel
                      {
                          Version = 3.0
                      }.DbInitialize();
            var foreignKeyBuilder = new ForeignKeyBuilder(database, "FK");

            var principalTable = new EntityType("P", XmlConstants.TargetNamespace_3, DataSpace.SSpace);

            foreignKeyBuilder.PrincipalTable = principalTable;

            var dependentTable = new EntityType("D", XmlConstants.TargetNamespace_3, DataSpace.SSpace);

            foreignKeyBuilder.SetOwner(dependentTable);

            Assert.NotNull(database.GetAssociationType("FK"));

            foreignKeyBuilder.SetOwner(null);

            Assert.Null(database.GetAssociationType("FK"));
        }
 internal void AddForeignKey(ForeignKeyBuilder foreignKeyBuilder)
 {
     Util.ThrowIfReadOnly((MetadataItem)this);
     foreignKeyBuilder.SetOwner(this);
     this._foreignKeyBuilders.Add(foreignKeyBuilder);
 }
예제 #17
0
        internal void AddForeignKey(ForeignKeyBuilder foreignKeyBuilder)
        {
            DebugCheck.NotNull(foreignKeyBuilder);
            Util.ThrowIfReadOnly(this);

            foreignKeyBuilder.SetOwner(this);

            _foreignKeyBuilders.Add(foreignKeyBuilder);
        }
        public void AssociationSet_TargetEnd_correct_after_setting_owner()
        {
            var database = new EdmModel(DataSpace.SSpace);

            var foreignKeyBuilder = new ForeignKeyBuilder(database, "FK");

            foreignKeyBuilder.PrincipalTable = database.AddTable("P");
            foreignKeyBuilder.SetOwner(database.AddTable("T"));

            var associationType = database.GetAssociationType("FK");
            var associationSet = database.GetAssociationSet(associationType);

            Assert.Equal("T", associationType.TargetEnd.Name);
            Assert.Equal("T", associationSet.TargetEnd.Name);

            foreignKeyBuilder.SetOwner(database.AddTable("T1"));

            Assert.Equal("T1", associationType.TargetEnd.Name);
            Assert.Equal("T1", associationSet.TargetEnd.Name);
        }
예제 #19
0
        public void Set_principal_table_when_self_ref_should_differentiate_target_end_name()
        {
            var database
                = new EdmModel
                      {
                          Version = 3.0
                      }.DbInitialize();
            var foreignKeyBuilder = new ForeignKeyBuilder(database, "FK");

            var table = new EntityType("T", XmlConstants.TargetNamespace_3, DataSpace.SSpace);

            foreignKeyBuilder.PrincipalTable = new EntityType("P", XmlConstants.TargetNamespace_3, DataSpace.SSpace);
            foreignKeyBuilder.SetOwner(table);

            var associationType = database.GetAssociationType("FK");

            Assert.Equal("P", associationType.SourceEnd.Name);
            Assert.Equal("T", associationType.TargetEnd.Name);

            foreignKeyBuilder.PrincipalTable = table;

            Assert.Same(table, associationType.SourceEnd.GetEntityType());
            Assert.Equal("T", associationType.SourceEnd.Name);
            Assert.Same(table, associationType.TargetEnd.GetEntityType());
            Assert.Equal("TSelf", associationType.TargetEnd.Name);
        }
 internal void RemoveForeignKey(ForeignKeyBuilder foreignKeyBuilder)
 {
     Util.ThrowIfReadOnly((MetadataItem)this);
     foreignKeyBuilder.SetOwner((EntityType)null);
     this._foreignKeyBuilders.Remove(foreignKeyBuilder);
 }
        public void SetOwner_when_self_ref_should_differentiate_target_end_name()
        {
            var database = new EdmModel(DataSpace.SSpace);

            var foreignKeyBuilder = new ForeignKeyBuilder(database, "FK");

            var table = database.AddTable("T");

            foreignKeyBuilder.PrincipalTable = table;
            foreignKeyBuilder.SetOwner(table);

            var associationType = database.GetAssociationType("FK");

            Assert.Same(table, associationType.SourceEnd.GetEntityType());
            Assert.Equal("T", associationType.SourceEnd.Name);
            Assert.Same(table, associationType.TargetEnd.GetEntityType());
            Assert.Equal("TSelf", associationType.TargetEnd.Name);
        }
예제 #22
0
        public void Can_get_and_set_delete_action()
        {
            var database
                = new EdmModel
                      {
                          Version = 3.0
                      }.DbInitialize();
            var foreignKeyBuilder = new ForeignKeyBuilder(database, "FK");

            var table = new EntityType("T", XmlConstants.TargetNamespace_3, DataSpace.SSpace);

            foreignKeyBuilder.PrincipalTable = table;
            foreignKeyBuilder.SetOwner(table);
            foreignKeyBuilder.DeleteAction = OperationAction.Cascade;

            var associationType = database.GetAssociationType("FK");

            Assert.Equal(OperationAction.Cascade, associationType.SourceEnd.DeleteBehavior);
        }
        public void Can_get_and_set_delete_action()
        {
            var database = new EdmModel(DataSpace.SSpace);

            var foreignKeyBuilder = new ForeignKeyBuilder(database, "FK");

            var table = database.AddTable("T");

            foreignKeyBuilder.PrincipalTable = table;
            foreignKeyBuilder.SetOwner(table);
            foreignKeyBuilder.DeleteAction = OperationAction.Cascade;

            var associationType = database.GetAssociationType("FK");

            Assert.Equal(OperationAction.Cascade, associationType.SourceEnd.DeleteBehavior);
        }
        public void Can_get_and_set_dependent_columns_and_multiplicities_assigned()
        {
            var database = new EdmModel(DataSpace.SSpace);

            var foreignKeyBuilder = new ForeignKeyBuilder(database, "FK");

            var table = database.AddTable("T");

            foreignKeyBuilder.PrincipalTable = table;
            foreignKeyBuilder.SetOwner(table);

            var property = EdmProperty.Primitive("K", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            foreignKeyBuilder.DependentColumns = new[] { property };

            Assert.Equal(1, foreignKeyBuilder.DependentColumns.Count());

            var associationType = database.GetAssociationType("FK");

            Assert.NotNull(associationType.Constraint);
            Assert.Same(property, associationType.Constraint.ToProperties.Single());
            Assert.Same(associationType.SourceEnd, associationType.Constraint.FromRole);
            Assert.Same(associationType.TargetEnd, associationType.Constraint.ToRole);
            Assert.Equal(RelationshipMultiplicity.Many, associationType.TargetEnd.RelationshipMultiplicity);
            Assert.Equal(RelationshipMultiplicity.ZeroOrOne, associationType.SourceEnd.RelationshipMultiplicity);

            property.Nullable = false;

            foreignKeyBuilder.DependentColumns = new[] { property };

            Assert.Equal(RelationshipMultiplicity.One, associationType.SourceEnd.RelationshipMultiplicity);
        }