Exemple #1
0
        /// <summary>
        /// Operates in an opposite capacity to its <see cref="AddToBlockedNameList(string)"/>
        /// in that only the names presented in <see cref="tblNames"/> will remain available
        /// and every table name found in <see cref="Sorting.AllTablesWithPkNames." />
        /// and <see cref="Sorting"/>, not being found therein, will be added to the
        /// blocked name list.
        /// </summary>
        /// <param name="tblNames">An exclusive list of table names by which all others are blocked.</param>
        /// <returns>The count of names present in the blocked names list.</returns>
        /// <remarks>
        /// The idea here is that some databases will actually have more tables you know you don't want
        /// than those that you do so its easier to just list those tables you do want.
        /// </remarks>
        public static int SetExclusiveNameList(string[] tblNames)
        {
            if (tblNames == null || tblNames.Length <= 0)
            {
                return(0);
            }

            var pkTbls     = Sorting.AllTablesWithPkNames;
            var noPkTables = Sorting.NoPkTablesNames;

            foreach (var tbl in pkTbls.Where(t => !DoNotReference.Any(x => String.Equals(x, t, StringComparison.OrdinalIgnoreCase)) &&
                                             !tblNames.Any(x => String.Equals(x, t, StringComparison.OrdinalIgnoreCase))))
            {
                var sameCaseTbl = pkTbls.FirstOrDefault(x => String.Equals(x, tbl, StringComparison.OrdinalIgnoreCase));
                if (sameCaseTbl == null)
                {
                    continue;
                }
                DoNotReference.Add(sameCaseTbl);
            }
            foreach (var tbl in noPkTables.Where(t => !DoNotReference.Any(x => String.Equals(x, t, StringComparison.OrdinalIgnoreCase)) &&
                                                 !tblNames.Any(x => String.Equals(x, t, StringComparison.OrdinalIgnoreCase))))
            {
                var sameCaseTbl = pkTbls.FirstOrDefault(x => String.Equals(x, tbl, StringComparison.OrdinalIgnoreCase));
                if (sameCaseTbl == null)
                {
                    continue;
                }
                DoNotReference.Add(sameCaseTbl);
            }

            return(DoNotReference.Count);
        }