/// <summary>
        /// Makes a shallow copy of the current GreyFoxContactCollection.
        /// as the parent object.
        /// </summary>
        /// <returns>GreyFoxContactCollection</returns>
        public GreyFoxContactCollection Clone()
        {
            GreyFoxContactCollection clonedGreyFoxContact = new GreyFoxContactCollection(count);

            lock (this)
            {
                foreach (GreyFoxContact item in this)
                {
                    clonedGreyFoxContact.Add(item);
                }
            }
            return(clonedGreyFoxContact);
        }
        /// <summary>
        /// Makes a deep copy of the current GreyFoxContact.
        /// </summary>
        /// <param name="isolation">Placeholders are used to isolate the
        /// items in the GreyFoxContactCollection from their children.</param>
        public GreyFoxContactCollection Copy(bool isolated)
        {
            GreyFoxContactCollection isolatedCollection = new GreyFoxContactCollection(count);

            lock (this)
            {
                if (isolated)
                {
                    for (int i = 0; i < count; i++)
                    {
                        isolatedCollection.Add(GreyFoxContactArray[i].NewPlaceHolder());
                    }
                }
                else
                {
                    for (int i = 0; i < count; i++)
                    {
                        isolatedCollection.Add(GreyFoxContactArray[i].Copy());
                    }
                }
            }
            return(isolatedCollection);
        }
        public GreyFoxContactCollection GetCollection(int topCount, string whereClause, string sortClause)
        {
            StringBuilder            query;
            Database                 database;
            DbCommand                dbCommand;
            IDataReader              r;
            GreyFoxContactCollection greyFoxContactCollection;


            query = new StringBuilder("SELECT ");

            if (topCount > 0)
            {
                query.Append("TOP ");
                query.Append(topCount);
                query.Append(" ");
            }

            foreach (string columnName in InnerJoinFields)
            {
                query.Append("GreyFoxContact.");
                query.Append(columnName);
                query.Append(",");
            }

            //
            // Remove trailing comma
            //
            query.Length--;
            query.Append(" FROM ");
            query.Append(tableName);
            query.Append(" AS GreyFoxContact");
            //
            // Render where clause
            //
            if (whereClause != string.Empty)
            {
                query.Append(" WHERE ");
                query.Append(whereClause);
            }

            //
            // Render sort clause
            //
            if (sortClause != string.Empty)
            {
                query.Append(" ORDER BY ");
                query.Append(sortClause);
            }

            //
            // Render final semicolon
            //
            query.Append(";");
            database  = DatabaseFactory.CreateDatabase();
            dbCommand = database.GetSqlStringCommand(query.ToString());
                        #if DEBUG
            try
            {
                r = database.ExecuteReader(dbCommand);
            }
            catch (Exception e)
            {
                string msg = e.Message;
                throw(new Exception(msg + " --- Query: " + query.ToString()));
            }
                        #else
            r = database.ExecuteReader(dbCommand);
                        #endif

            greyFoxContactCollection = new GreyFoxContactCollection();

            while (r.Read())
            {
                GreyFoxContact greyFoxContact = ParseFromReader(tableName, r, 0, 1);

                greyFoxContactCollection.Add(greyFoxContact);
            }

            // Microsoft DAAB still needs to close readers.
            r.Close();

            return(greyFoxContactCollection);
        }