/// <summary>
        /// Initializes a new instance of the <see cref="AttributedAssociation"/> class.
        /// </summary>
        /// <param name="name">The association name.</param>
        /// <param name="cardinality">The cardinality of the association. Note this may also be 1:1 or 1:n,
        /// as these might also be defined as 'attributed'.</param>
        /// <param name="destinationForeignKeyName">Name of the destination foreign key.</param>
        /// <param name="destinationForeignKeyType">Type of the destination foreign key.</param>
        /// <param name="destinationPrimaryKey">The destination primary key.</param>
        /// <param name="originForeignKeyName">Name of the origin foreign key.</param>
        /// <param name="originForeignKeyType">Type of the origin foreign key.</param>
        /// <param name="originPrimaryKey">The origin primary key.</param>
        public AttributedAssociation([NotNull] string name,
                                     AssociationCardinality cardinality,
                                     [NotNull] string destinationForeignKeyName,
                                     FieldType destinationForeignKeyType,
                                     [NotNull] ObjectAttribute destinationPrimaryKey,
                                     [NotNull] string originForeignKeyName,
                                     FieldType originForeignKeyType,
                                     [NotNull] ObjectAttribute originPrimaryKey)
            : base(name, cardinality)
        {
            Assert.ArgumentNotNullOrEmpty(destinationForeignKeyName,
                                          nameof(destinationForeignKeyName));
            Assert.ArgumentNotNullOrEmpty(originForeignKeyName, nameof(originForeignKeyName));
            Assert.NotNullOrEmpty(destinationPrimaryKey.Name);
            Assert.NotNullOrEmpty(originPrimaryKey.Name);

            AssociationAttribute destinationForeignKey = AddAttribute(
                destinationForeignKeyName, destinationForeignKeyType);
            AssociationAttribute originForeignKey = AddAttribute(
                originForeignKeyName, originForeignKeyType);

            // TODO should be renamed to AttributedAssociationEnd! cardinality may also be 1:1 or 1:n
            DestinationEnd = new ManyToManyAssociationEnd(this, destinationForeignKey,
                                                          destinationPrimaryKey);
            OriginEnd = new ManyToManyAssociationEnd(this, originForeignKey,
                                                     originPrimaryKey);
        }
        public AssociationAttribute AddAttribute([NotNull] string name,
                                                 FieldType fieldType)
        {
            Assert.ArgumentNotNullOrEmpty(name, nameof(name));

            foreach (AssociationAttribute existingAttribute in _attributes)
            {
                if (string.Equals(existingAttribute.Name, name,
                                  StringComparison.OrdinalIgnoreCase))
                {
                    throw new ArgumentException(
                              string.Format("Attribute with same name already exists: {0}",
                                            name), nameof(name));
                }
            }

            ClearAttributeMaps();

            var attribute = new AssociationAttribute(name, fieldType)
            {
                Association = this
            };

            _attributes.Add(attribute);

            _msg.DebugFormat("Added attribute {0} to attributed association {1}", name, Name);

            return(attribute);
        }
        public void RemoveAttribute([NotNull] AssociationAttribute attribute)
        {
            Assert.ArgumentNotNull(attribute, nameof(attribute));

            ClearAttributeMaps();

            _attributes.Remove(attribute);
            attribute.Association = null;
        }
Beispiel #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ManyToManyAssociationEnd"/> class.
        /// </summary>
        /// <param name="association">The association.</param>
        /// <param name="foreignKey">The foreign key.</param>
        /// <param name="primaryKey">The primary key.</param>
        public ManyToManyAssociationEnd([NotNull] AttributedAssociation association,
                                        [NotNull] AssociationAttribute foreignKey,
                                        [NotNull] ObjectAttribute primaryKey)
            : base(association, primaryKey.Dataset, false)
        {
            Assert.ArgumentNotNull(foreignKey, nameof(foreignKey));
            Assert.ArgumentNotNull(primaryKey, nameof(primaryKey));

            _foreignKey = foreignKey;
            _primaryKey = primaryKey;
        }