/// <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); }
/// <summary> /// Initializes a new instance of the <see cref="Association"/> class. /// </summary> /// <param name="name">The name of the relationship class.</param> /// <param name="cardinality">The cardinality.</param> protected Association([NotNull] string name, AssociationCardinality cardinality) { Assert.ArgumentNotNullOrEmpty(name, nameof(name)); AssertValidCardinality(cardinality); Name = name; _cardinality = cardinality; }
public static Association CreateAssociation( [NotNull] IRelationshipClass relClass, [NotNull] IObjectDataset destinationDataset, [NotNull] IObjectDataset originDataset, [NotNull] Model model) { bool unqualifyDatasetName = !model.HarvestQualifiedElementNames; string relClassName = DatasetUtils.GetName(relClass); AssociationCardinality cardinality = GetCardinality(relClass); ObjectAttribute originPK = GetOriginPK(relClass, originDataset); string associationName = !unqualifyDatasetName ? relClassName : ModelElementNameUtils.GetUnqualifiedName(relClassName); if (!relClass.IsAttributed && relClass.Cardinality != esriRelCardinality.esriRelCardinalityManyToMany) { ObjectAttribute originFK = GetOriginFK(relClass, destinationDataset); return(new ForeignKeyAssociation(associationName, cardinality, originFK, originPK) { Model = model }); } ObjectAttribute destinationPK = GetDestinationPK( relClass, destinationDataset); var relTable = (ITable)relClass; esriFieldType destinationFKType = DatasetUtils.GetField( relTable, relClass.DestinationForeignKey).Type; esriFieldType originFKType = DatasetUtils.GetField( relTable, relClass.OriginForeignKey).Type; return(new AttributedAssociation( associationName, cardinality, relClass.DestinationForeignKey, (FieldType)destinationFKType, destinationPK, relClass.OriginForeignKey, (FieldType)originFKType, originPK) { Model = model }); }
/// <summary> /// Initializes a new instance of the <see cref="ForeignKeyAssociation"/> class. /// </summary> /// <param name="name">The name.</param> /// <param name="cardinality">The association cardinality.</param> /// <param name="foreignKey">The foreign key (on destination table).</param> /// <param name="primaryKey">The primary key (on origin table).</param> public ForeignKeyAssociation([NotNull] string name, AssociationCardinality cardinality, [NotNull] ObjectAttribute foreignKey, [NotNull] ObjectAttribute primaryKey) : base(name, cardinality) { Assert.ArgumentNotNull(foreignKey, nameof(foreignKey)); Assert.ArgumentNotNull(primaryKey, nameof(primaryKey)); Assert.NotNullOrEmpty(foreignKey.Name, "fk name is null"); Assert.NotNullOrEmpty(primaryKey.Name, "pk name is null"); DestinationEnd = new ForeignKeyAssociationEnd(this, foreignKey); OriginEnd = new PrimaryKeyAssociationEnd(this, primaryKey); }
protected override bool IsValidCardinality(AssociationCardinality cardinality) { switch (cardinality) { case AssociationCardinality.Unknown: case AssociationCardinality.ManyToMany: return(false); case AssociationCardinality.OneToOne: case AssociationCardinality.OneToMany: return(true); default: throw new ArgumentOutOfRangeException(nameof(cardinality), cardinality, @"Unexpected cardinality"); } }
private void AssertValidCardinality(AssociationCardinality cardinality) { Assert.ArgumentCondition(IsValidCardinality(cardinality), "Unsupported cardinality"); }
protected abstract bool IsValidCardinality(AssociationCardinality cardinality);