src/Misc/EFTools/EntityDesignEntityDesigner/CustomCode/Diagram/EntityDesignerDiagram.cs
/// <summary>
///     Creates new association for given EntityTypeShape
/// </summary>
Creates new association for given EntityTypeShape
Creates new association for given EntityTypeShape
[SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
        internal void AddNewAssociation(EntityTypeShape entityShape)
        {
            if ((Partition.GetLocks() & Locks.Add) == Locks.Add)
            {
                return;
            }
            ViewModelEntityType end1 = null;
            if (entityShape != null)
            {
                end1 = entityShape.ModelElement as ViewModelEntityType;
            }
            if (end1 == null)
            {
                end1 = ModelElement.EntityTypes[0];
            }
            ViewModelEntityType end2 = null;
            var index = ModelElement.EntityTypes.IndexOf(end1) + 1;
            if (ModelElement.EntityTypes.Count <= index)
            {
                index = 0;
            }
            end2 = ModelElement.EntityTypes[index];
            var modelEnd1Entity = ModelElement.ModelXRef.GetExisting(end1) as Model.Entity.EntityType;
            var modelEnd2Entity = ModelElement.ModelXRef.GetExisting(end2) as Model.Entity.EntityType;
            Debug.Assert(modelEnd1Entity != null && modelEnd2Entity != null);
            var model = modelEnd1Entity.Parent as ConceptualEntityModel;
            Debug.Assert(model != null);
            using (var dialog = new NewAssociationDialog(model.EntityTypes(), modelEnd1Entity, modelEnd2Entity))
            {
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        Store.RuleManager.DisableRule(typeof(Association_AddRule));
                        using (var t = Store.TransactionManager.BeginTransaction(EntityDesignerResources.Tx_AddAssociation))
                        {
                            t.Context.Add(EfiTransactionOriginator.TransactionOriginatorDiagramId, DiagramId);
                            ViewModelChangeContext.GetNewOrExistingContext(t).ViewModelChanges.Add(new Association_AddFromDialog(dialog));
                            t.Commit();
                        }
                    }
                    finally
                    {
                        Store.RuleManager.EnableRule(typeof(Association_AddRule));
                    }
                }
            }
        }
[ SuppressMessage ( " " , " " ) ] internal void AddNewAssociation ( EntityTypeShape entityShape ) { if ( ( Partition . GetLocks ( ) & Locks . Add ) == Locks . Add ) { return ; } ViewModelEntityType end1 = null ; if ( entityShape != null ) { end1 = entityShape . ModelElement as ViewModelEntityType ; } if ( end1 == null ) { end1 = ModelElement . EntityTypes [ 0 ] ; } ViewModelEntityType end2 = null ; var index = ModelElement . EntityTypes . IndexOf ( end1 ) + 1 ; if ( ModelElement . EntityTypes . Count <= index ) { index = 0 ; } end2 = ModelElement . EntityTypes [ index ] ; var modelEnd1Entity = ModelElement . ModelXRef . GetExisting ( end1 ) as Model . Entity . EntityType ; var modelEnd2Entity = ModelElement . ModelXRef . GetExisting ( end2 ) as Model . Entity . EntityType ; Debug . Assert ( modelEnd1Entity != null && modelEnd2Entity != null ) ; var model = modelEnd1Entity . Parent as ConceptualEntityModel ; Debug . Assert ( model != null ) ; using ( var dialog = new NewAssociationDialog ( model . EntityTypes ( ) , modelEnd1Entity , modelEnd2Entity ) ) { if ( dialog . ShowDialog ( ) == DialogResult . OK ) { try { Store . RuleManager . DisableRule ( typeof ( Association_AddRule ) ) ; using ( var t = Store . TransactionManager . BeginTransaction ( EntityDesignerResources . Tx_AddAssociation ) ) { t . Context . Add ( EfiTransactionOriginator . TransactionOriginatorDiagramId , DiagramId ) ; ViewModelChangeContext . GetNewOrExistingContext ( t ) . ViewModelChanges . Add ( new Association_AddFromDialog ( dialog ) ) ; t . Commit ( ) ; } } finally { Store . RuleManager . EnableRule ( typeof ( Association_AddRule ) ) ; } } } }
Creates new association for given EntityTypeShape
Creates new association for given EntityTypeShape
// If user selected an EntityTypeShape, use corresponding EntityType // else default to first EntityType in the model // Pick something for the second end (defaulting to the next EntityType in the model)
entityShape
EntityTypeShape