// Set the connection string in temporary storage
        // Returns true if the metadata was successfully loaded for the specified connections
        internal bool SelectConnectionStringBuilder(EntityConnectionStringBuilderItem selectedConnection, bool resetContainer)
        {
            _selectedConnectionStringBuilder = selectedConnection;

            bool metadataLoaded = false;
            if (selectedConnection != null)
            {
                if (selectedConnection.EntityConnectionStringBuilder != null)
                {
                    metadataLoaded = _helper.LoadMetadata(selectedConnection.EntityConnectionStringBuilder);                    
                }
                else
                {
                    // Since we don't have a valid connection string builder, we don't have enough information to load metadata.
                    // Clear any existing metadata so we don't see an old item collection on any subsequent calls that access it.
                    // Don't need to display an error here because that was handled by the caller who created the builder item
                    _helper.ClearMetadata();                    
                }
            }

            // Reset the list of containers if requested and set the ComboBox to have no selection.
            // In some cases the containers do not need to be reset because the caller wants to delay that until a later event or wants to preserve a specific value
            if (resetContainer)
            {
                string defaultContainerName = _selectedConnectionStringBuilder.EntityConnectionStringBuilder == null ? null : _selectedConnectionStringBuilder.EntityConnectionStringBuilder.Name;
                LoadContainerNames(defaultContainerName, false /*initialLoad*/);
            }
            
            // Update the controls
            UpdateWizardState();

            return metadataLoaded;
        }
        // Expects that the specified builder item is a named connection already in the list, is a full connection string, or is empty
        // If empty, the default is to select the named connection option and don't select anything in the list
        internal void SetConnectionString(EntityConnectionStringBuilderItem connStrBuilderItem)
        {
            Debug.Assert(connStrBuilderItem != null, "expected non-null connStrBuilderItem");

            _ignoreEvents = true;

            // set the state of the ConnectionString radio buttons and associated controls
            bool isNamedConnection = connStrBuilderItem.IsEmpty || connStrBuilderItem.IsNamedConnection; 
           
            _namedConnectionRadioButton.Checked = isNamedConnection;
            _namedConnectionComboBox.Enabled = isNamedConnection;
            _connectionStringRadioButton.Checked = !isNamedConnection;
            _connectionStringTextBox.Enabled = !isNamedConnection;

            // set the value of the control that was just enabled
            if (connStrBuilderItem.IsEmpty)
            {
                _namedConnectionComboBox.SelectedIndex = -1;
                _configureObjectContext.SelectConnectionStringHasValue(false /*connectionStringHasValue*/);
            }
            else if (connStrBuilderItem.IsNamedConnection)
            {
                _namedConnectionComboBox.SelectedItem = connStrBuilderItem;
                _configureObjectContext.SelectConnectionStringHasValue(true /*connectionStringHasValue*/);
            }
            else
            {
                _connectionStringTextBox.Text = connStrBuilderItem.ConnectionString;
                _configureObjectContext.SelectConnectionStringHasValue(!connStrBuilderItem.IsEmpty);
            }

            _ignoreEvents = false;
        }
        // Find the current named connection in the list of connections
        // The returned item may refer to the same connection as the specified item, but it will be the actual reference from the list
        private EntityConnectionStringBuilderItem FindCurrentNamedConnection(EntityConnectionStringBuilderItem newBuilderItem)
        {
            Debug.Assert(_namedConnections != null, "_namedConnections should have already been initialized and should not be null");
            Debug.Assert(newBuilderItem != null && newBuilderItem.IsNamedConnection, "expected non-null newBuilderItem");

            foreach (EntityConnectionStringBuilderItem namedConnectionItem in _namedConnections)
            {
                if (((IComparable<EntityConnectionStringBuilderItem>)newBuilderItem).CompareTo(namedConnectionItem) == 0)
                {
                    // returning the one that was actually in the list, so we can select it in the control
                    return namedConnectionItem;
                }
            }

            // didn't find it in the list, so add it
            _namedConnections.Add(newBuilderItem);
            return newBuilderItem;            
        }