private static void DeleteStaleAssociations(CommandProcessorContext cpc, BaseEntityModel model, HashSet <string> associationNames)
        {
            Debug.Assert(model != null, "Model was null, could not delete stale Fks between Pks");
            if (model != null)
            {
                var associationsToDelete = new List <Association>();

                foreach (var association in model.Associations())
                {
                    // If this association is longer present in the latest SqlSchema model, delete it
                    if (associationNames.Contains(association.Name.Value) == false)
                    {
                        associationsToDelete.Add(association);
                    }
                }

                foreach (var association in associationsToDelete)
                {
                    var deleteAssociationSetCommand = new DeleteEFElementCommand(
                        (c, subCpc) =>
                    {
                        var cmd       = c as DeleteEFElementCommand;
                        cmd.EFElement = ModelHelper.FindAssociationSet(model, association.Name.Value);
                        return(cmd.EFElement != null);
                    });

                    CommandProcessor.InvokeSingleCommand(cpc, deleteAssociationSetCommand);

                    var deleteAssociationCmd = new DeleteAssociationCommand(
                        (c, subCpc) =>
                    {
                        var cmd = c as DeleteAssociationCommand;
                        // Checking the model again for the association in case it's deleted already.
                        cmd.EFElement = ModelHelper.FindAssociation(model, association.Name.Value);
                        return(cmd.EFElement != null);
                    });

                    CommandProcessor.InvokeSingleCommand(cpc, deleteAssociationCmd);
                }
            }
        }
        private static void DeleteStaleAssociations(CommandProcessorContext cpc, BaseEntityModel model, HashSet<string> associationNames)
        {
            Debug.Assert(model != null, "Model was null, could not delete stale Fks between Pks");
            if (model != null)
            {
                var associationsToDelete = new List<Association>();

                foreach (var association in model.Associations())
                {
                    // If this association is longer present in the latest SqlSchema model, delete it
                    if (associationNames.Contains(association.Name.Value) == false)
                    {
                        associationsToDelete.Add(association);
                    }
                }

                foreach (var association in associationsToDelete)
                {
                    var deleteAssociationSetCommand = new DeleteEFElementCommand(
                        (c, subCpc) =>
                            {
                                var cmd = c as DeleteEFElementCommand;
                                cmd.EFElement = ModelHelper.FindAssociationSet(model, association.Name.Value);
                                return cmd.EFElement != null;
                            });

                    CommandProcessor.InvokeSingleCommand(cpc, deleteAssociationSetCommand);

                    var deleteAssociationCmd = new DeleteAssociationCommand(
                        (c, subCpc) =>
                            {
                                var cmd = c as DeleteAssociationCommand;
                                // Checking the model again for the association in case it's deleted already.
                                cmd.EFElement = ModelHelper.FindAssociation(model, association.Name.Value);
                                return cmd.EFElement != null;
                            });

                    CommandProcessor.InvokeSingleCommand(cpc, deleteAssociationCmd);
                }
            }
        }
 internal override DeleteEFElementCommand GetDeleteCommand()
 {
     var cmd = new DeleteAssociationCommand(this);
     Debug.Assert(cmd != null, "Could not create DeleteAssociationCommand, falling back to base class delete.");
     if (cmd == null)
     {
         // shouldn't happen, just to be safe
         return base.GetDeleteCommand();
     }
     return cmd;
 }