Example #1
0
        public ModelType AddNewDataContext(string typeName)
        {
            if (typeName == null)
            {
                throw new ArgumentNullException("typeName");
            }

            if (AddedDataContextItem != null)
            {
                DataContextType     = null;
                DataContextTypeName = null;
                DataContextTypesInternal.Remove(AddedDataContextItem);
            }

            AddedDataContextItem = new ModelType(typeName);
            DataContextTypesInternal.Add(AddedDataContextItem);
            return(AddedDataContextItem);
        }
        /// <summary>
        /// Adds a DataContext item with the given name.
        /// </summary>
        /// <param name="typeName">The full type name of the DataContext to add.</param>
        /// <returns>The newly created item.</returns>'
        /// <remarks>
        /// We'll only generate a single DataContext item as a result of scaffolding. If the user previously
        /// selected 'new' and then did it again, we'll remove the item that was added the first time.
        /// </remarks>
        public ModelType AddNewDataContext(string typeName)
        {
            if (typeName == null)
            {
                throw new ArgumentNullException("typeName");
            }

            if (AddedDataContextItem != null)
            {
                // If the selected datacontext is removed from the collection, DataContextType will be set as the
                // value before the deleted value from the collection. If the selected datacontext name and previous datacontext
                // name are the same, the combo box will not be updated with the newly selected datacontext name but the previous
                // value from the collection. Hence, setting the datacontext to null before removing the previously added datacontext
                // from the collection.
                DataContextType     = null;
                DataContextTypeName = null;
                DataContextTypesInternal.Remove(AddedDataContextItem);
            }

            AddedDataContextItem = new ModelType(typeName);
            DataContextTypesInternal.Add(AddedDataContextItem);
            return(AddedDataContextItem);
        }