Ejemplo n.º 1
0
        internal void AddAssociation(AssociationDefinition associationDefinition)
        {
            var association = new Association(this, associationDefinition);

            // Defensive programming to prevent unexpected behavior caused by "missing" extensions
            if (_finalizedAggregateFullNameByEntityFullName.IsValueCreated)
            {
                throw new InvalidOperationException(
                          $"Association '{association.FullName}' is being added after the domain model has been processed for extension entities.");
            }

            if (_associationByFullName.ContainsKey(association.FullName))
            {
                throw new Exception($"Association '{association.FullName}' already exists.");
            }

            _associationByFullName.Add(association.FullName, association);
            _associations.Add(association);

            var primaryAssociation = new AssociationView(this, association, true);

            AddAssociationView(primaryAssociation, association.PrimaryEntityFullName);

            var secondaryAssociation = new AssociationView(this, association, false);

            AddAssociationView(secondaryAssociation, association.SecondaryEntityFullName);

            primaryAssociation.Inverse   = secondaryAssociation;
            secondaryAssociation.Inverse = primaryAssociation;
        }
Ejemplo n.º 2
0
        private void AddAssociationView(AssociationView associationView, FullName entityName)
        {
            List <AssociationView> associationViews;

            if (!_associationViewsByEntityNameMutable.TryGetValue(entityName, out associationViews))
            {
                associationViews = new List <AssociationView>();
                _associationViewsByEntityNameMutable[entityName] = associationViews;
            }

            associationViews.Add(associationView);
        }